SpringBoot2-Activiti7
SpringBoot2-Activiti7 copied to clipboard
设计器保存接口报400错误
我的请求如下:
Request URL: http://192.168.31.10:9090/service/model/25834baa-7a08-11ea-9a35-025041000101/save
Request Method: PUT
Status Code: 400
Remote Address: 192.168.31.161:9090
Referrer Policy: no-referrer-when-downgrade
.....
Connection: keep-alive
Content-Length: 60176
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
示例部分请求
返回的结果如下:
{"timestamp":"2020-04-09T07:33:17.789+0000","status":400,"error":"Bad Request","message":"Required request body is missing: public void com.zjialin.workflow.activiti.ModelSaveRestResource.saveModel(java.lang.String,org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>)","path":"/service/model/25834baa-7a08-11ea-9a35-025041000101/save"}
分析原因是:
由于发送的请求使用的是:
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
而该接口使用的@RequestBody注解 来接收提交的4个参数,这个注册是作用于请求是按
application/json 方式发送请求的,所在用该注解是无法接收到参数的,所以会报400的错误
正解的修改方式是在com.zjialin.workflow.activiti.ModelSaveRestResource 类中保存接口修改如下
@RequestMapping(value = {"/service/model/{modelId}/save"}, method = {org.springframework.web.bind.annotation.RequestMethod.PUT})
@ResponseStatus(HttpStatus.OK)
public void saveModel(@RequestParam MultiValueMap<String, String> values, @PathVariable String modelId) {
....
知识点参考: 获取接口请求中的参数(@PathVariable,@RequestParam,@RequestBody)
