Guest User

Untitled

a guest
Jan 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. @Entity
  2. @Table(name = "cliente")
  3. public class Cliente implements Serializable {
  4.  
  5. @Id
  6. @GeneratedValue(strategy = GenerationType.AUTO)
  7. private long id;
  8. private String nome;
  9. private String empresa;
  10.  
  11. public long getId() {
  12. return id;
  13. }
  14.  
  15. public void setId(long id) {
  16. this.id = id;
  17. }
  18.  
  19. public String getNome() {
  20. return nome;
  21. }
  22.  
  23. public void setNome(String nome) {
  24. this.nome = nome;
  25. }
  26.  
  27. public String getEmpresa() {
  28. return empresa;
  29. }
  30.  
  31. public void setEmpresa(String empresa) {
  32. this.empresa = empresa;
  33. }
  34. }
  35.  
  36. @Repository
  37. public interface ClienteRespository extends JpaRepository<Cliente, Long> {
  38.  
  39. }
  40.  
  41. public interface ClienteService {
  42.  
  43. Cliente save(Cliente cliente);
  44. }
  45.  
  46. @Service
  47. public class ClienteServiceImpl implements ClienteService {
  48.  
  49. @Autowired
  50. ClienteRespository clienteRepository;
  51.  
  52. @RolesAllowed(value = "ROLE_USER")
  53. @Override
  54. public Cliente save(Cliente cliente) {
  55. return clienteRepository.save(cliente);
  56. }
  57.  
  58. }
  59.  
  60. @Controller
  61. public class WebController {
  62.  
  63. @Autowired
  64. ClienteService clienteService;
  65.  
  66. @RequestMapping("/")
  67. public String home() {
  68. return "index";
  69. }
  70.  
  71. @RequestMapping(name = "/salvar", method = RequestMethod.GET)
  72. public String salvar() {
  73. Cliente cliente = new Cliente();
  74. cliente.setNome("Carlos");
  75. cliente.setEmpresa("Logic");
  76.  
  77. clienteService.save(cliente);
  78.  
  79. return "redirect:/";
  80. }
  81.  
  82. <!DOCTYPE html>
  83. <html>
  84. <head>
  85. <title>Página Inicial</title>
  86. <meta charset="UTF-8">
  87. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  88. </head>
  89. <body>
  90. <div>Página Inicial</div><br />
  91. </body>
  92. </html>
  93.  
  94. #Perfil
  95. spring.profiles.active=dev
  96.  
  97. #Banco de Dados
  98. spring.datasource.url=jdbc:postgresql://localhost:5432/bancoteste
  99. spring.datasource.username=postgres
  100. spring.datasource.password=postgres
  101.  
  102. #JPA
  103. spring.jpa.hibernate.ddl-auto=create-drop
  104. spring.jpa.show-sql=true
  105.  
  106. #fix jpa postgres
  107. spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Add Comment
Please, Sign In to add comment