M
M
MisterParser2018-12-28 13:09:38
Java
MisterParser, 2018-12-28 13:09:38

How to make automatic mapping of one value to a list in RestController Spring parameters?

How to make callMethod work when passing in POST parameters both array "[1,2,3]" and single value "1"?

@RequestMapping("/api/")
@RestController
public class MyController {
    @PostMapping("/callMethod")
    public void callMethod(@RequestBody List<Long> ids) {

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sadrutdin Zainukov, 2018-12-29
@sandro6661

Maybe you made the request incorrectly? Works for me with the latest Spring Boot:

@RestController
@RequestMapping("")
public class IndexController {
    @PostMapping("")
    public void index(@RequestParam List<Long> ids){
        System.out.println(ids);
    }
}

curl --request POST --url 'http://localhost:8080/?ids=11'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question