In Spring, how do I bind a list of integers to a RequestParam?
The problem you are facing is that java has type erasure. So at runtime a List<Integer>
is equivalent than a List<String>
and spring has no way of knowing you want Integers into your list.
A work around might be using a integer array instead of a List of integers.
@RequestMapping("/delete.x")public @ResponseBody Map<String, Object> delete(HttpServletRequest request, @RequestParam("ids[]") Integer[] ids) {
For string I have done like this and this running properly
<form action="addArticals"> <input name="artical[]" type="text"> </input> <input name="artical[]" type="text"> </input> <input name="artical[]" type="text"> </input> <input name="artical[]" type="text"> </input> . . . . <input name="artical[]" type="text"> </input></form>
and in controller it will be like this
@RequestMapping("/addArticals")public String articalStore(@RequestParam("artical[]")List<String> articals, Modal modal){}