Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestController
- public class CandidatosWS {
- @Autowired
- CandidatoService candidatoService;
- @RequestMapping(value = "/candidatos/", method = RequestMethod.GET)
- public ResponseEntity<List<Candidato>> allCandidatos() {
- List<Candidato> listCandidatos = null;
- try {
- listCandidatos = candidatoService.listarCandidatos();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new ResponseEntity<List<Candidato>>(listCandidatos, HttpStatus.OK);
- }
- }
- <html>
- <head>
- <title>Error</title>
- </head>
- <body>Not Acceptable</body>
- </html>
- @RequestMapping(value = "/candidatos/", method = RequestMethod.GET)
- @RequestMapping(value = "/candidatos/", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
- List<JSONObject> listCandidatos = new ArrayList<JSONObject>();
- return new ResponseEntity<List<JSONObject>>(listCandidatos, HttpStatus.OK);
- @RequestMapping(value = "/candidatos/", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<List<Candidato>> allCandidatos() {
- List<Candidato> listCandidatos = /* busca de candidatos*/
- List<JSONObject> listCandidatosJson = new ArrayList<JSONObject>();
- for (Candidato cand : listCandidatos ) {
- JSONObject candidatoJson = cand.toJson(); //implemente o método toJson(), conforme sugerido
- listCandidatosJson.add(candidatoJson);
- }
- return new ResponseEntity<List<JSONObject>>(listCandidatosJson, HttpStatus.OK);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement