4
I’m having a dumb doubt in some exercises using Spring Boot.
The exercise requires that I receive the list of numbers as follows:
http://localhost:8080/listaDecrescente?lista={12,55,70,22}
And return the answer:
HTTP 200 OK {70,55,22,12}
Ok, the logic is simple. My question is: how do I pass the parameters between the keys, like the above example?
Like I’m doing:
@RequestMapping(value = {"/listaDecrescente"})
public int[] listaDecrescente(@RequestParam int[] lista){
//lógica aqui...
return lista;
}
The only way my URL accepts receiving data:
http://localhost:8080/api/listaDecrescente?lista=12,55,70,22
Hello, I’m new in spring... but try
List<Integer>
. Your @Requestmapping is strange, so those {} on the outside? should be "/{list}". In the last case you will have to read as String and do the parse in the same hand... But it must have better shape. Still, I give a star to those who link me where in the spring documentation it lists which are the mappings between java types and "parsers" of spring controller. Because, for example, if you pass a DTO on a body it parses and validates automatically with the validation annotations, where it is documented?– wkrueger