@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("{idinst: [0-9]+ }/, { tipopersona}/")
public List<String> obtenCorreosDeInstitucion(@PathParam("idinst") long idinst,@PathParam("tipopersona") String tipo){
List<String> resultado=new ArrayList<>();
List<Persona> persona=obtenerPersona();
int length=persona.size();
int i=0;
while(i<length){
if(persona.get(i).getTipoPersona().equals(tipo)){
if(persona.get(i).getIdInstitucionPersona()==idinst){
resultado.add(persona.get(i).getEmailPersona());
}
}
i++;
}
return resultado;
}
public List<Persona> obtenerPersona(){
List<Persona> resultado=new ArrayList<>();
try{
Query q = em.createQuery("SELECT p FROM Persona p");
Persona p = (Persona) q.getResultList();
resultado= (List<Persona>) q.getResultList();
System.out.println(resultado);
}
catch(NoResultException ex){
}
return resultado;
}
So I have the code like this, but on the tests, it says 404 not found, but the other methods in this class do pass the tests, so I am assuming something in my path is not right, can someone please point me in the right direction? I have searched up on the internet and I can only find examples for when it's only one variable value you get from the path.
Try the following (it seems to me that you have extra ,
in your @Path
annotation):
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("{idinst: [0-9]+ }/{tipopersona}/")
public List<String> obtenCorreosDeInstitucion(@PathParam("idinst") long idinst,@PathParam("tipopersona") String tipo){
List<String> resultado=new ArrayList<>();
List<Persona> persona=obtenerPersona();
int length=persona.size();
int i=0;
while(i<length){
if(persona.get(i).getTipoPersona().equals(tipo)){
if(persona.get(i).getIdInstitucionPersona()==idinst){
resultado.add(persona.get(i).getEmailPersona());
}
}
i++;
}
return resultado;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.