json格式500错误
页面错误信息

2.json.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>json</title>
</head>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
var course = {
"id":"8",
"name":"SSM框架整合",
"price":"200"
};
$.ajax({
url:"jsonType",
data:JSON.stringify(course),
type:"post",
contentType:"application/json;charset=UTF-8",
dataType:"json",
success:function(data){
alert(data.name+"---"+data.price);
}
})
})
</script>
<body>
</body>
</html>3.Controller
@RequestMapping(value = "/jsonType")
@ResponseBody
public Course jsonType(@RequestBody Course course){
course.setPrice(course.getPrice()+100);
return course;
}4.pom文件依赖
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.1.5</version> </dependency>
5.springmvc.xml设置
<context:component-scan base-package="com.imooc"></context:component-scan> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean> </mvc:message-converters> </mvc:annotation-driven>
1
收起
正在回答 回答被采纳积分+1
1回答
chrismorgen
2018-11-02 14:32:10
同学在idea的控制台中有没有报错呢?如果有,建议把报错提示粘贴上来,方便我们具有针对性的为你解答,祝学习愉快~
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星