我读过this answer是因为我的问题与问题类似,但是现在我陷入了困境。
通过邮递员,我以这种方式发送数据:
在春季,我像这样检索它们:
@PostMapping(path = PathConstants.START_ACTION, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<BaseResponse<ProcessInstance>> start(@PathVariable String processDefinitionId,
@RequestParam("username") String params) {
这可以正常工作,我可以打印用户名的值:
System.out.println("Username " + params);
问题是我需要发送的所有参数,但是我无法将它们作为字符串或任何其他对象来获取,因为我将提出许多不同的请求,并且并非所有请求都具有“用户名”领域,顺便说一下,我需要收集所有这些。
我该如何实现?
我已经尝试过了
@PostMapping(path = PathConstants.START_ACTION, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<BaseResponse<ProcessInstance>> start(@PathVariable String processDefinitionId,
@RequestParam String params) {
或
@PostMapping(path = PathConstants.START_ACTION, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<BaseResponse<ProcessInstance>> start(@PathVariable String processDefinitionId,
String params) {
如其他答案所建议,但在这些情况下,params为空。什么是正确的工作方式?
答案 0 :(得分:1)
您的方法中需要@RequestBody
批注,我建议您使用MultiValueMap
:
@PostMapping(path = PathConstants.START_ACTION, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<BaseResponse<ProcessInstance>> start(@PathVariable String processDefinitionId, @RequestBody MultiValueMap<String, String> params)