Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package pe.com.labo.web.controller;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. import org.springframework.http.ResponseEntity;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.ui.Model;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.client.RestTemplate;
  12.  
  13. import pe.com.labo.web.entity.Paciente;
  14.  
  15. @Controller
  16. @RequestMapping("/pacientes")
  17. public class PacienteController {
  18.  
  19. private static final String URL = "http://localhost:8081/pacientes";
  20.  
  21. @GetMapping
  22. public String mainOrden(Model model) {
  23. try {
  24. // objeto que consume el servicio
  25. RestTemplate restTemplate = new RestTemplate();
  26. ResponseEntity<Paciente[]> response = restTemplate.getForEntity(URL, Paciente[].class);
  27. List<Paciente> pacientes = Arrays.asList(response.getBody());
  28.  
  29. model.addAttribute("pacientes",pacientes);
  30. } catch (Exception e) {
  31. // TODO: handle exception
  32. }
  33. model.addAttribute("mensaje","Este mensaje lo envié desde el Controller");
  34. return "/pacientes/mainPaciente";
  35. }
  36.  
  37. @GetMapping("/create")
  38. public String createOrden(Model model) {
  39. model.addAttribute("mensaje","Aquí se crearán las órdenes");
  40. return "/pacientes/createPaciente";
  41. }
  42.  
  43. @GetMapping("/edit")
  44. public String editOrden(Model model) {
  45. model.addAttribute("mensaje","Aquí se crearán las órdenes");
  46. return "/pacientes/editPaciente";
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement