Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. @RestController
  2. public class CandidatosWS {
  3.  
  4. @Autowired
  5. CandidatoService candidatoService;
  6.  
  7. @RequestMapping(value = "/candidatos/", method = RequestMethod.GET)
  8. public ResponseEntity<List<Candidato>> allCandidatos() {
  9. List<Candidato> listCandidatos = null;
  10.  
  11. try {
  12. listCandidatos = candidatoService.listarCandidatos();
  13. } catch (Exception e) {
  14. e.printStackTrace();
  15. }
  16.  
  17. return new ResponseEntity<List<Candidato>>(listCandidatos, HttpStatus.OK);
  18. }
  19. }
  20.  
  21. <html>
  22. <head>
  23. <title>Error</title>
  24. </head>
  25. <body>Not Acceptable</body>
  26. </html>
  27.  
  28. @RequestMapping(value = "/candidatos/", method = RequestMethod.GET)
  29.  
  30. @RequestMapping(value = "/candidatos/", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
  31.  
  32. List<JSONObject> listCandidatos = new ArrayList<JSONObject>();
  33.  
  34. return new ResponseEntity<List<JSONObject>>(listCandidatos, HttpStatus.OK);
  35.  
  36. @RequestMapping(value = "/candidatos/", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
  37. public ResponseEntity<List<Candidato>> allCandidatos() {
  38.  
  39. List<Candidato> listCandidatos = /* busca de candidatos*/
  40.  
  41. List<JSONObject> listCandidatosJson = new ArrayList<JSONObject>();
  42. for (Candidato cand : listCandidatos ) {
  43. JSONObject candidatoJson = cand.toJson(); //implemente o método toJson(), conforme sugerido
  44. listCandidatosJson.add(candidatoJson);
  45. }
  46.  
  47. return new ResponseEntity<List<JSONObject>>(listCandidatosJson, HttpStatus.OK);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement