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"
報錯原因:

  

 

解決方法:

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);
}

  




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM