Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package model;
  2. public class Cliente {
  3.  
  4. private String nome;
  5. private String cpf;
  6. private Integer idade;
  7. private String sexo;
  8.  
  9. public Cliente(String nome, String cpf, Integer idade, String sexo) {
  10. this.nome = nome;
  11. this.cpf = cpf;
  12. this.idade = idade;
  13. this.sexo = sexo;
  14. }
  15.  
  16. public String getNome() {
  17. return nome;
  18. }
  19.  
  20. public void setNome(String nome) {
  21. this.nome = nome;
  22. }
  23.  
  24. public String getCpf() {
  25. return cpf;
  26. }
  27.  
  28. public void setCpf(String cpf) {
  29. this.cpf = cpf;
  30. }
  31.  
  32. public Integer getIdade() {
  33. return idade;
  34. }
  35.  
  36. public void setIdade(Integer idade) {
  37. this.idade = idade;
  38. }
  39.  
  40. public String getSexo() {
  41. return sexo;
  42. }
  43.  
  44. public void setSexo(String sexo) {
  45. this.sexo = sexo;
  46. }
  47.  
  48. @Override
  49. public String toString() {
  50. return "Cliente [nome=" + nome + ", cpf=" + cpf + ", idade=" + idade + ", sexo=" + sexo + "]";
  51. }
  52. }
  53.  
  54. package controller;
  55.  
  56. import java.util.Hashtable;
  57. import org.springframework.beans.factory.annotation.Autowired;
  58. import org.springframework.http.MediaType;
  59. import org.springframework.web.bind.annotation.PathVariable;
  60. import org.springframework.web.bind.annotation.RequestMapping;
  61. import org.springframework.web.bind.annotation.RequestMethod;
  62. import org.springframework.web.bind.annotation.RestController;
  63. import model.Cliente;
  64. import service.ClienteService;
  65.  
  66. @RestController
  67. @RequestMapping("/clientes")
  68. public class ClienteController {
  69.  
  70.  
  71. @Autowired
  72. ClienteService cli;
  73.  
  74. @RequestMapping("/all")
  75. public Hashtable<String, Cliente> getAll(){
  76. return cli.getAll();
  77. }
  78.  
  79. //não esta buscando desta forma
  80. @RequestMapping("{nome}")
  81. public Cliente getCliente(@PathVariable("nome") String nome){
  82. return cli.getCliente(nome);
  83. }
  84. }
  85.  
  86. package service;
  87. import java.util.Hashtable;
  88. import org.springframework.stereotype.Service;
  89. import model.Cliente;
  90.  
  91. @Service
  92. public class ClienteService {
  93. Hashtable<String, Cliente> clientes = new Hashtable<String, Cliente> ();
  94.  
  95. public ClienteService(){
  96.  
  97. Cliente c1 = new Cliente("paulo","123.123.123-22",28,"M");
  98. Cliente c2 = new Cliente("diego","123.123.123-22",24,"M");
  99. Cliente c3 = new Cliente("Debora","123.123.123-22",21,"F");
  100.  
  101. clientes.put("1", c1);
  102. clientes.put("2", c2);
  103. clientes.put("3", c3);
  104.  
  105. }
  106.  
  107. public Cliente getCliente(String nome){
  108. if(clientes.containsKey(nome)){
  109. return clientes.get(nome);
  110. }else{
  111. return null;
  112. }
  113.  
  114. }
  115. public Hashtable<String, Cliente> getAll(){
  116. return clientes;
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement