I am new to JAVA Springboot and I have an error when trying to send a json by GET.
For the tests I use POSTMAN and this error sends me:
{
"status": "INTERNAL_SERVER_ERROR",
"message": "Required request parameter 'tags' for method parameter type List is not present"
}
json to prove:
"tags": [
"potable",
"contaminada",
"tratada"
]
The layers are quite simple:
Controller:
@GetMapping("/search")
public ResponseEntity<List<PropuestaEntity>> SearchTags(@RequestParam("tags") List<String> tag) {
List<PropuestaEntity> propuesta = propuestaServices.SearchTags(tag);
return ResponseEntity.ok(propuesta);
}
Services:
public List<PropuestaEntity> SearchTags(List<String> tag) {
return propuestaRepository.findByTags(tag);
}
Repository:
public interface PropuestaRepository extends MongoRepository<PropuestaEntity, Integer> {
List<PropuestaEntity> findByTags(List<String> tag);
}
Data in mongobd:
{
"titulo": "Análisis de la calidad del agua en el río X sdauiyuadiossd",
"tags": ["agua", "calidad", "contaminación", "metales pesados", "nutrientes"],
"estadoPropuesta":1
}
The main objective is to search for Proposals (English) by the tags that were previously assigned to them and list all the proposals containing those tags.
> searchByTags(@RequestBody Map> body) {
List tags = body.get("tags");
List propuestas = propuestaServices.SearchTags(tags);
return ResponseEntity.ok(propuestas);
}
its work, in repository FindbyTagsIn(list<>, tags)
Thanks @Seelenvirtuose
– marcelo sazo Apr 26 '23 at 06:22