springboot + restful + nginx + tomcat后台接收不到post参数

  • 问题
    环境:springboot + restful + nginx + tomcat
@PostMapping(value = "/illegalOperation")
    @ApiOperation(httpMethod = "POST", value = "客户端webSocket中断", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account",value = "坐席账户名",required = true,paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "userPhone",value = "坐席登录分机号",required = true,paramType = "query",dataType = "string")
    })
    public VueReturn doIllegalOperation(String account,String userPhone){
        logger.info("PhoneBarRecordController invoked doIllegalOperation with parameters: account={},userPhone={}",account,userPhone);
        if (!StringUtils.isNotBlank(account) || !StringUtils.isNotBlank(userPhone)) {
            return setFailResult(ConstantsUtils.STRING_ZERO, "坐席账户名和坐席分机号必须");
        }
        BaseUsers user = usersService.findUserByAccount(account);
        if (null != user) {
            PhoneBarRecord record = new PhoneBarRecord();
            record.setUserId(user.getUserId());
            record.setAccount(user.getAccount());
            record.setUserPhone(userPhone);
            record.setOpName(ConstantsUtils.PHONE_BAR_STATUS_NAME_LOGOUT);
            record.setOpCode(ConstantsUtils.PHONE_BAR_STATUS_CODE_LOGOUT);
            record.setRemark("PhoneBar provider invoked.");
            String result = this.phoneBarRecordService.save(record);
            if (result.equalsIgnoreCase(ConstantsUtils.STRING_ZERO)) {
                logger.info("PhoneBarRecordController invoked doIllegalOperation with save success.");
                return setFailResult(ConstantsUtils.STRING_ZERO,result);
            }
            return setSuccessResult(ConstantsUtils.STRING_ONE,"save success!");
        }
        return setFailResult(ConstantsUtils.STRING_ZERO, "用户不存在");
    }

测试:PostMan
采用: raw , application/json :
{
“account”:“111”,
“userPhone”:“222”
}
在后台接收数据全部为null

把环境 springboot + restful + nginx + tomcat
更换为 springboot + restful + tomcat 一切正常

一度怀疑是nginx 与 tomcat 请求存在转换差异。

  • 解决
    采用 application/x-www-form-urlencoded ,一切正常。

  • 分析
    主要是@requestParam 和 @requestBody 区别
    @requestParam 绑定单个请求数据,可以是URL中的数据,表单提交的数据或上传的文件;
    @RequestBody,用来处理Content-Type不是application/x-www-form-urlencoded编码的内容,例如application/json, application/xml等

猜你喜欢

转载自blog.csdn.net/quanaianzj/article/details/83114436
今日推荐