springboot集成springData Jpa

8.springboot集成springData Jpa

8.1添加springData Jpa的起步依赖

springboot集成springData Jpa_第1张图片

             

                     org.springframework.boot

                     spring-boot-starter-data-jpa

             

 

 

添加数据库坐标

springboot集成springData Jpa_第2张图片

             

                     mysql

                     mysql-connector-java

             

 

 

 

8.2添加配置文件

 

数据库配置信息

#DB Configuration:

spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8

spring.datasource.username=root

spring.datasource.password=root

 

 

 

 

Jpa

springboot集成springData Jpa_第3张图片

#JPA Configuration:

spring.jpa.database=MySQL

spring.jpa.show-sql=true

spring.jpa.generate-ddl=true

spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy

 

 

 

 

8.3配置domain.User

@Entity注解

//主键

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

springboot集成springData Jpa_第4张图片

 

 

8.4创建repository

springboot集成springData Jpa_第5张图片

 

 

你可能感兴趣的:(springboot)