解决@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();
Springboot在接收前端实体时,可以在后端建立相应的对象来直接接受,在此可以不使用@RequestBody(只能接收josn的对象)@RequestPrama接收单个字段,而非对象实体!
栏 目:JAVA代码
下一篇:springboot新建项目pom.xml文件第一行报错的解决
本文标题:解决@RequestBody使用不能class类型匹配的问题
本文地址:http://www.codeinn.net/misctech/193079.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




