SpringBoot中SpringDataJpa自动生成表结构

  1. 加入SpringDataJpa的Pom文件
<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-data-jpaartifactId>
    <version>1.5.15.RELEASEversion>
dependency>
<dependency>
     <groupId>org.springframework.datagroupId>
     <artifactId>spring-data-jpaartifactId>
     <version>1.11.14.RELEASEversion>
dependency>
  1. 在配置文件中配置数据库连接
spring.datasource.url=jdbc:mysql://*****:3306/******?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=******
spring.datasource.password=*******
  1. 在配置文件中声明自动生成表结构
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
  1. 在实体类中加入注解以及生命表名称(注意导包不要导错了)
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="student")
public class Student{

    private String name;

    private String age;
	………
	………

注:别忘记包扫描的时候要扫描到该包
在springboot的启动类上加上注解

@EntityScan(basePackages={"com.***.***.domain"})

这样在SpringBoot工程启动的时候就可以生成表结构了

你可能感兴趣的:(springboot,SpringDataJpa,SpringDataJpa)