Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pe.com.labo.web.controller;
- import java.util.Arrays;
- import java.util.List;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.client.RestTemplate;
- import pe.com.labo.web.entity.Paciente;
- @Controller
- @RequestMapping("/pacientes")
- public class PacienteController {
- private static final String URL = "http://localhost:8081/pacientes";
- @GetMapping
- public String mainOrden(Model model) {
- try {
- // objeto que consume el servicio
- RestTemplate restTemplate = new RestTemplate();
- ResponseEntity<Paciente[]> response = restTemplate.getForEntity(URL, Paciente[].class);
- List<Paciente> pacientes = Arrays.asList(response.getBody());
- model.addAttribute("pacientes",pacientes);
- } catch (Exception e) {
- // TODO: handle exception
- }
- model.addAttribute("mensaje","Este mensaje lo envié desde el Controller");
- return "/pacientes/mainPaciente";
- }
- @GetMapping("/create")
- public String createOrden(Model model) {
- model.addAttribute("mensaje","Aquí se crearán las órdenes");
- return "/pacientes/createPaciente";
- }
- @GetMapping("/edit")
- public String editOrden(Model model) {
- model.addAttribute("mensaje","Aquí se crearán las órdenes");
- return "/pacientes/editPaciente";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement