Spring Data JPA如何为?

摘要:Spring Data JPA build.gradle plugins { id 'org.springframework.boot' version '2.7.0&
Spring Data JPA build.gradle plugins { id 'org.springframework.boot' version '2.7.0' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group = 'com.insight.into.life' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-actuator' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } tasks.named('test') { useJUnitPlatform() } 添加 org.springframework.boot:spring-boot-starter-web org.springframework.boot:spring-boot-starter-data-jpa mysql:mysql-connector-java application.yml server: port: 9000 logging: level: org.springframework.security: info spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/auth-center?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai username: root password: 123456 jpa: hibernate: ddl-auto: update spring.jpa.hibernate.ddl-auto 的参数可选项有 none:使用 mysql 数据库时,默认值为 none,对数据库表不会产生任何影响 update:Hibernate 根据实体变更表结构 create:每次都会重新创建表,但是应用程序关闭时,不会删除表 create-drop:创建表,应用程序关闭时,删除表。
阅读全文