/**
* 访问数据库 jsp页面 jq 代码
*/
function accessDb() {
var allData = $('#dg').datagrid('getData');
var rows = allData.rows;
// rows = [Object { year="2015",income="2",grossProfit="2",更多...}, Object {year="2016", income="2",grossProfit="2",更多...}]
$.ajax({
cache : false,
type : 'POST',
contentType:"application/json",// 指定传输协议 发送信息至服务器时内容编码类型。(这个必须要指定)
dataType : 'json', //服务器返回的数据,将以什么方式进行解析。
url : 'p2p/saveEnterpriseFinance',
async : false,
data :JSON.stringify(rows), //转成字符串形式
error : function(XMLHttpRequest, textStatus) {
assertSessionTimeOut(XMLHttpRequest, textStatus);
errorAlert('警告',
'<spring:message code="message.requestInterrupt"/>');
},
success : function(data) {
}
});
}
/**
* test Controller 接收写法
*
* @parambeanList
* @return
*/
@RequestMapping("saveEnterpriseFinance")
@ResponseBody
public EnterpriseFinanceBeansaveEnterpriseFinance(@RequestBody List<EnterpriseFinanceBean>beanList) {
System.out.println(beanList);
return null;
}
/ 以下是 常见的异常信息/
contentType:“application/json",// 指定传输协议 发送信息至服务器时内容编码类型。
第一种异常 如果在jqajax把contentType去掉 java中就会报如下常信息
=====================================
[com.jrd.resolver.CustomHandlerExceptionResolver]org.springframework.web.HttpMediaTypeNotSupportedException:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
[com.jrd.resolver.CustomHandlerExceptionResolver]
=====================================
第二种异常 无法读取JSON:无法识别的 字段; json中的status字段 在这个bean中不存在
=====================================
[com.jrd.resolver.CustomHandlerExceptionResolver]org.springframework.http.converter.HttpMessageNotReadableException:Could not read JSON: Unrecognized field "status"(Classcom.jrd.controller.p2p.bean.EnterpriseFinanceBean),notmarked as ignorable
at [Source:org.apache.catalina.connector.CoyoteInputStream@136f5849; line: 1, column: 13](through reference chain:com.jrd.controller.p2p.bean.EnterpriseFinanceBean["status"]); nestedexception isorg.codehaus.jackson.map.exc.UnrecognizedPropertyException:Unrecognized field "status" (Classcom.jrd.controller.p2p.bean.EnterpriseFinanceBean), not marked as ignorable
at [Source:org.apache.catalina.connector.CoyoteInputStream@136f5849; line: 1, column: 13](through reference chain:com.jrd.controller.p2p.bean.EnterpriseFinanceBean["status"])
[com.jrd.resolver.CustomHandlerExceptionResolver]
=====================================