同個接口既使用@PathVariable接收url中的參數,又使用@RequestBody接收前端的對象


后端的最外層接口:使用的是POST請求方式

 @ApiOperation("添加學生管理_學生信息_學生課程等級")
    @RequestMapping(value = "/create/{studentCourseGradeMergeId}", method = RequestMethod.POST)
    Result<?> create(@ApiParam(value = "學生等級類別合並ID") java.lang.String studentCourseGradeMergeId,
    		@ApiParam(value = "學生ID") java.lang.String[] studentIds);

 controller層使用的是:

@Override
	public Result<?> create(@PathVariable("studentCourseGradeMergeId") String studentCourseGradeMergeId,
			@RequestBody java.lang.String[] studentIds) {
		SystemUserInfo systemUserInfo = SessionUtil.getSystemUserInfo(request); // 獲取用戶信息
		String userId = "";
		if (systemUserInfo != null) {
			userId = systemUserInfo.getUserId(); // 用戶Id
		}
		studentGradeService.batchCreate(userId, studentCourseGradeMergeId, studentIds);
		return Result.buildSuccessResult();
	}

  前端傳遞的是:其中formData.courseGradeCategoryCode是url路徑中的一部分,studentIds是傳遞的數組也就是對象

// 批量添加學生等級
    batchOnSubmit = () => {
        this.refs.addModal.validateFields((err, formData) => {
            if (!err) {
                let studentIds = this.child.state.selectedRowKeys; // 獲取到選中記錄的學生ID
                studentGradeCreate(formData.courseGradeCategoryCode,studentIds, () => {
                  this.onSearch();
                    this.showAddModal();
                    this.setState({
                        selectedRowKeys: []
                    })
                });
            }
        });
    };

  前端抽取出來的service層是:

// 添加學生管理_學生信息_學生課程等級管理
export function studentGradeCreate(param,data, callback) {
    post(studentGradeApi.create + '/'+ param, data).then(response => {
        if (response.code == '200') {
            message.info('添加成功');
            callback();
        } else {
            if (response.message) {
                message.error(response.message);
            } else {
                message.error('添加失敗');
            }
        }
    });
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM