Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name = "cliente")
- public class Cliente implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private long id;
- private String nome;
- private String empresa;
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getNome() {
- return nome;
- }
- public void setNome(String nome) {
- this.nome = nome;
- }
- public String getEmpresa() {
- return empresa;
- }
- public void setEmpresa(String empresa) {
- this.empresa = empresa;
- }
- }
- @Repository
- public interface ClienteRespository extends JpaRepository<Cliente, Long> {
- }
- public interface ClienteService {
- Cliente save(Cliente cliente);
- }
- @Service
- public class ClienteServiceImpl implements ClienteService {
- @Autowired
- ClienteRespository clienteRepository;
- @RolesAllowed(value = "ROLE_USER")
- @Override
- public Cliente save(Cliente cliente) {
- return clienteRepository.save(cliente);
- }
- }
- @Controller
- public class WebController {
- @Autowired
- ClienteService clienteService;
- @RequestMapping("/")
- public String home() {
- return "index";
- }
- @RequestMapping(name = "/salvar", method = RequestMethod.GET)
- public String salvar() {
- Cliente cliente = new Cliente();
- cliente.setNome("Carlos");
- cliente.setEmpresa("Logic");
- clienteService.save(cliente);
- return "redirect:/";
- }
- <!DOCTYPE html>
- <html>
- <head>
- <title>Página Inicial</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <div>Página Inicial</div><br />
- </body>
- </html>
- #Perfil
- spring.profiles.active=dev
- #Banco de Dados
- spring.datasource.url=jdbc:postgresql://localhost:5432/bancoteste
- spring.datasource.username=postgres
- spring.datasource.password=postgres
- #JPA
- spring.jpa.hibernate.ddl-auto=create-drop
- spring.jpa.show-sql=true
- #fix jpa postgres
- spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Add Comment
Please, Sign In to add comment