若是前台将Object对象,使用JSON.stringify(obj)转成Json字符串,并依此请急求后台时,其中java
contentType : application/x-www-form-urlencoded ,该属性为表单提交的默认类型。
spring
使用Spring Mvc接收参数和Request 接收参数有所不一样:app
Spring Mvc接收参数: 会对Json字符串中的""进行转义,而request.getParamter()不会。
url
示例:
code
前台代码:orm
var testObj=new Object();
testObj.name='abc';
testObj.age='8';
var testJson=JSON.stringify(testObj);
console.log(conditionsJson);
lrDgLeftGrid.datagrid('load',{
'testJson':testJson
});
对象
后台代码:字符串
@RequestMapping(value="/testJson") @ResponseBody public DataGrid testJson(PageHelper ph, String testJson,HttpServletRequest request) throws Exception { System.out.println("spring="+testJson); System.out.println("getParamter="+request.getParameter("testJson")); }
后台输出:get
spring={"name":"abc","age":"8"} getParamter={"name":"abc","age":"8"}