在SpringMVC中,为什么我的@RequestParam消失了?

时间:2018-03-29 06:30:49

标签: java spring rest spring-mvc

我在SpringMVC中发现了一个奇怪的问题。我使用postman发送请求

these details

但是当我调试时,我看到this

为什么状态变为“状态”?

这是我的代码:

@RequestMapping(value = "/publishCallback" , method = {RequestMethod.POST, 
RequestMethod.GET})
@ResponseBody
public ResponseData publicCallback( PublishCallBackVo publishCallBackVo, 
HttpServletRequest request) throws Exception {
    logger.info("传入的请求参数"+request.getParameterMap());
    String status_ = request.getParameterMap().get("status ")[0];
    publishCallBackVo.setStatus(status_);
    projectPublishService.publishCallBack(publishCallBackVo);
    return ResponseData.success();
}

public class PublishCallBackVo {
    private String id;
    private String status;
    private String project;
    private String envType;
    private String result;
    private String projectType;
    private String tarName;
    private String appTag;
    private String deployType;
    private String ip;

2 个答案:

答案 0 :(得分:2)

从此行代码中删除[0]

String status_ = request.getParameterMap().get("status ")[0];

注意:在获取状态后您有空格。

因此代码将成为

String status_ = request.getParameterMap().get("status");

原因:
Link
如果这不起作用,就像您按列表一样访问它,那么请在代码中将[0]替换为[1]。如果有效,请告诉我。

答案 1 :(得分:0)

您可以尝试以下方法:

@RequestMapping(value = "/publishCallback" , method = {RequestMethod.POST, 
RequestMethod.GET})
@ResponseBody
public ResponseData publicCallback( PublishCallBackVo publishCallBackVo, 
HttpServletRequest request) throws Exception {
logger.info("传入的请求参数"+request.getParameterMap());
String status_ = request.getParameterMap().get("status ");
if(status_!=null && status_!=""){
  publishCallBackVo.setStatus(status_);
  projectPublishService.publishCallBack(publishCallBackVo);
}
return ResponseData.success();
}