Como otimizar filtros utilizando @RequestParam no Spring Boot
Boa Tarde, qual documentação que ensina a otimizar @RequestParam com multiplos filtros. Estou tentando encontrar na web mas esta difícil. Se alguém puder me ajudar com essa informação ou uma breve explicação de um método melhor, obrigado.
Para entender melhor o que estou querendo , segue uma parte do meu repository e controller.
___________________________________________________________________________________________________________________________________________________________________________
Repository
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public List<Schedules> queryFilter(List<Integer>iid, List<Integer>gid) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("iid", iid);
parameters.addValue("gid", gid);
return namedParameterJdbcTemplate.query("""
select
at.internal_description as incident,
s.internal_description as specialty,
count(a.specialty_id) as total
from appointment a
join appointment_type at on (at.id = a.appointment_type_id)
join specialty s on (s.id = a.specialty_id)
join patient p on (p.id=a.patient_id)
join gender g on (g.id=p.gender_id)
where
a.institution_id in (:iid)
and g.id in (:gid)
Group by
at.internal_description,
s.internal_description""", parameters,
______________________________________________________________________________________________________________________________________________________________________________
Controller
@RequestMapping("/filter")
@ResponseBody
public List<Schedules> queryCountSpecialtyFilter(
@RequestParam (value = "iid", required = false) List<Integer> iid,
@RequestParam (value = "gid", required = false) List<Integer> gid
){
return this.schedulesService.queryFilter(iid,gid);
}
Para entender melhor o que estou querendo , segue uma parte do meu repository e controller.
___________________________________________________________________________________________________________________________________________________________________________
Repository
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public List<Schedules> queryFilter(List<Integer>iid, List<Integer>gid) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("iid", iid);
parameters.addValue("gid", gid);
return namedParameterJdbcTemplate.query("""
select
at.internal_description as incident,
s.internal_description as specialty,
count(a.specialty_id) as total
from appointment a
join appointment_type at on (at.id = a.appointment_type_id)
join specialty s on (s.id = a.specialty_id)
join patient p on (p.id=a.patient_id)
join gender g on (g.id=p.gender_id)
where
a.institution_id in (:iid)
and g.id in (:gid)
Group by
at.internal_description,
s.internal_description""", parameters,
______________________________________________________________________________________________________________________________________________________________________________
Controller
@RequestMapping("/filter")
@ResponseBody
public List<Schedules> queryCountSpecialtyFilter(
@RequestParam (value = "iid", required = false) List<Integer> iid,
@RequestParam (value = "gid", required = false) List<Integer> gid
){
return this.schedulesService.queryFilter(iid,gid);
}
Edson Lima
Curtidas 0