当前位置:主页 > 软件编程 > JAVA代码 >

解决@RequestBody使用不能class类型匹配的问题

时间:2022-02-11 10:02:24 | 栏目:JAVA代码 | 点击:

@RequestBody不能class类型匹配

在首次第一次尝试使用@RequestBody注解

开始加载字符串使用post提交(貌似只能post),加Json数据格式传输的时候,

 data:{"stockCode":"601288","startTime":"2011-11-10 09:05","endTime":"2019-11-20 09:10"}",
  type: "POST",
     contentType: "application/json",

这么做是完全没有问题

但是当尝试注入到一个class里面,怎么都进不去,直接报不允许加载,最后发现在小xml里面需要加上

<mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

并且修改

data:"{\"stockCode\":\"601288\",\"startTime\":\"2011-11-10 09:05\",\"endTime\":\"2019-11-20 09:10\"}",

这样是没有问题的!

@RequestBody 注意的问题

contentType : "application/json", //只能是这个

RequestBody 不能和form/data共存:

@RequestMapping(value = "/api/user/platform/report", method = RequestMethod.POST)
public ReturnData reportPlatform(RequestParamBean bean) {        //自定义接受实体RequestParamBean 

   logger.info("--------------首次登陆开始----------------");
   try {
      bean.getDeviceFigure();      

您可能感兴趣的文章:

相关文章