sping中的controller 接收带list的实体参数 nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

发布时间:2022-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了sping中的controller 接收带list的实体参数 nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

sping中的controller接收实体参数时如果实体中存在list属性,当list数值过大时报错

public class Model{
    private List<String> strings;
}

报错信息:"Invalid property 'rynrlist[256]' of bean class [com.ac.intellsecurity.model.exam.records.ExamTrainingRecordsModel]: Index of out of bounds in property path 'rynrlist[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256"报错原因:

  

sping中的controller 接收带list的实体参数 nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

 

解决方法:

1.修改成jsonobject 接参数 然后转成实体(推荐使用)

@RestController
@RequestMapping("/controller")
public class Controller {

    //原来的(修改前)
    @PostMapping("/addModel")
        public AjaxResult addModel(Model model){
        //.........
    }

    //修改后
    @PostMapping("/addModel")
    public AjaxResult addModel(JSONObject json){
        //.........
        Model model = JSONObject.parseObject(json.toJSONString(),Model.class);
    }
}    

  

2. controller中添加方法

@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.setAutoGrowNestedPaths(true);
    binder.setAutoGrowCollectionLimit(1024);
}

  

脚本宝典总结

以上是脚本宝典为你收集整理的sping中的controller 接收带list的实体参数 nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256全部内容,希望文章能够帮你解决sping中的controller 接收带list的实体参数 nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: