Spring MVC 前台向后台传递 对象集合 (一)

 /**

     * 访问数据库 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",// 指定传输协议 发送信息至服务器时内容编码类型

第一种异常 如果在jqajaxcontentType去掉 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]

=====================================




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值