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