纯属个人经验勿喷!
如果在springmvc 框架中 需要发送的请求返回的是对象的json格式 ,
1、已然配置了mvc-dispatcher-servlet.xml 里配置了
<mvc:annotation-driven/>
已然配置了maven的pom.xml 里的
jackson-databind、ackson-core、ackson-annotations、代码:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.7.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.7.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.7.4</version> </dependency>2、已然在方法上加了@ResponseBodyjava 代码:@ResponseBody @RequestMapping(value = "getloginUserName", method = RequestMethod.POST) public UserEntity getloginUserName() { UserEntity user = (UserEntity) request.getSession().getAttribute("user"); return user; }反正该配的都配了
js请求代码
$.ajax({ type: "post", url: "getloginUserName", data: "json=" + params, cache: false, async: false, dataType: "json", contentType: "application/json", timeout: 30000, success: function (data) { alert( data); } });
反正该配的都配了
但是!!!!!!!!!!!
虽然java方法进入了,but tmd返回的对象 到了前段就是报错500,(具体返回信息忘记了记,真的不想在整回前面错的版本)
这个时候可以想想有可能是
com.fasterxml.jackson.core和spring的版本冲突的问题了。。。。
在出错前配置的spring版本是
<properties><spring.version>4.2.6.RELEASE</spring.version> <hibernate.version>5.1.0.Final</hibernate.version></properties>上网查个别说是版本问题
然后更改 com.fasterxml.jackson.core 版本从2.9 一直换到了1.x 依然爆出错误。。
大爷的!调整了一天多。。看到有文章给出的是spring 的4.2.5.RELEASE 配2.7.4 的com.fasterxml.jackson.core调整后<properties> <spring.version>4.2.5.RELEASE</spring.version> <hibernate.version>4.3.2.Final</hibernate.version> </properties>运行正常。总结一句。。。。反正spring 的4.2.5.RELEASE 配2.7.4 的com.fasterxml.jackson.core是可以的至于spring 的4.2.6.RELEASE以上的 配任何版本的 的com.fasterxml.jackson.core是否有冲突虽然我试了本地有问题 但是 不敢妄言, 只能说 I dont know !!!如果有大神知道具体哪个跟哪个冲突可以分享分享谢谢!!!