org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-data-jpa mysql mysql-connector-java runtime com.alibaba druid 1.1.10
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTCspring.datasource.username=rootspring.datasource.password=rootspring.datasource.driverClassName= com.mysql.jdbc.Driverspring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.jpa.hibernate.ddl-auto=updatespring.jpa.show-sql=true
@Entity@Table(name="t_user")public class JpaUser { @Column(name="name") private String name ; @Column(name="address") private String address ; @Column(name="id") @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id ; @Column(name="age1") private Integer age ; @Column(name="age11") private Integer age1 ; public JpaUser(String name, String address, Integer age, Integer age1,Integer id) { this.name = name; this.address = address; this.age = age; this.age1 = age1; this.id = id; } public JpaUser() { }}
public interface JpaUserRespotory extends JpaRepository{}
@RunWith(SpringJUnit4ClassRunner.class)@SpringBootTest(classes = springBoot.class)public class JpaTest { @Autowired JpaUserRespotory jpaUserRespotory ; @Test public void test1 () { JpaUser jpaUser = new JpaUser("名称","地址",10,20,40); jpaUserRespotory.save(jpaUser); }}