贴上代码
---------------------后端代码-----------------------
@
RequestMapping(value="/testJson")
@
ResponseBody public TestJsonClass testJson(@RequestBody TestJsonClass testJsonClass){
System.out.println("yyy");
System.out.println(testJsonClass.getName());
TestJsonClass jjj=new TestJsonClass("jjj");
return jjj;
}
-------------------------TestJsonClass 类-----------------------
public class TestJsonClass {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public TestJsonClass(String name) {
super();
this.name = name;
}
}
----------------------------前端代码-------------------------------
<!-- json&ajax 测试 -->
<br><br>
<form id="myForm">
链接:<input type="text" id="name" name="name"/>
<br>
<input type="button" id="select" value="提交"/>
</form>
<script type="text/javascript">
$("#select").click(function() {
$.ajax({
url : "testJson",
type : "POST",
contentType : "application/json;charset=UTF-8",
"data": '{"name": "uname"}',
success:function(result) {
alert(result.name);
}
});
});
</script>