Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.eventoapp.repository;
- import org.springframework.data.repository.CrudRepository;
- import org.springframework.stereotype.Repository;
- import com.eventoapp.models.Evento;
- @Repository
- public interface EventoRepository extends CrudRepository<Evento, String>{
- Evento findByCodigo(long codigo);
- }
- package com.eventoapp.controllers;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import com.eventoapp.models.Evento;
- import com.eventoapp.repository.EventoRepository;
- @Controller
- public class EventoController {
- @Autowired
- EventoRepository er;
- @RequestMapping(value="/cadastrarEvento", method=RequestMethod.GET)
- public String form() {
- return "evento/formEvento";
- }
- @RequestMapping(value="/cadastrarEvento", method=RequestMethod.POST)
- public String form(Evento evento) {
- er.save(evento);
- return "redirect:/cadastrarEvento";
- }
- }
- package com.eventoapp.eventoapp;
- import javax.sql.DataSource;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.context.annotation.Profile;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.jpa.JpaVendorAdapter;
- import org.springframework.orm.jpa.vendor.Database;
- import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
- @Configuration
- public class DataConfiguration {
- @Bean
- public DataSource dataSource(){
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/eventosapp");
- dataSource.setUsername("root");
- dataSource.setPassword("hednf8iw");
- return dataSource;
- }
- @Bean
- public JpaVendorAdapter jpaVendorAdapter(){
- HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
- adapter.setDatabase(Database.MYSQL);
- adapter.setShowSql(true);
- adapter.setGenerateDdl(true);
- adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
- adapter.setPrepareConnection(true);
- return adapter;
- }
- }
Add Comment
Please, Sign In to add comment