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

浙公网安备 33010602011771号