美文网首页我爱编程
jquery提交数据时一个数字转字符问题

jquery提交数据时一个数字转字符问题

作者: 雨中的单车 | 来源:发表于2018-06-05 18:24 被阅读0次

    $.ajax({

    type:"POST",

    url:$("#op_type").val(),

    data: {

    "dparent_id":$("#dparent_id").val()

    }

    })

    通过以上方式向后台服务提供数据时,出现一下问题

    org.springframework.beans.InvalidPropertyException: Invalid property 'dparent_id[]' of bean class [com.omt.systemManagement.dto.FuncInfoDto]: Property referenced in indexed property path 'dparent_id[]' is neither an array nor a List nor a Map; returned value was []

    当$("#dparent_id").val()参数是一个数字时,后台spring架构接到的参数会默认转换为一个数组,导致传入参数出错,因为我后端定义的dparent_id参数为String类型。这时需要在前段的jquery方法中将$("#dparent_id").val()参数做一下转换,将数字转换为字符。

    如下:

    $("#dparent_id").val().toString() 

    当需要在js中将字符转换为整数可以使用parseInt()函数。

    相关文章

      网友评论

        本文标题:jquery提交数据时一个数字转字符问题

        本文链接:https://www.haomeiwen.com/subject/ofemsftx.html