server:
port: 8088
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=UTF8&useSSL=false
username: root
password: 密码
#部分一
jpa:
show-sql: true
hibernate:
ddl-auto: update
#部分2
properties:
hibernate:
#这个参数 一定要注意对应去配置 也可以不要它 就要上面 的部分一的
dialect: org.hibernate.dialect.MySQLDialect
所有测试环境依赖我都放在最后
实体类配置

注解解释
-
name name属性定义了被标注字段在数据库表中所对应字段的名称;
unique
unique属性表示该字段是否为唯一标识,默认为false。如果表中有一个字段需要唯一标识,则既可以使用该标记,也可以使用@Table标记中的@UniqueConstraint。nullable nullable属性表示该字段是否可以为null值,默认为true。
insertable insertable属性表示在使用“INSERT”脚本插入数据时,是否需要插入该字段的值。
updatable
updatable属性表示在使用“UPDATE”脚本插入数据时,是否需要更新该字段的值。insertable和updatable属性一般多用于只读的属性,例如主键和外键等。这些字段的值通常是自动生成的。columnDefinition
columnDefinition属性表示创建表时,该字段创建的SQL语句,一般用于通过Entity生成表定义时使用。(也就是说,如果DB中表已经建好,该属性没有必要使用。)table table属性定义了包含当前字段的表名。
length length属性表示字段的长度,当字段的类型为varchar时,该属性才有效,默认为255个字符。
precision和scale
precision属性和scale属性表示精度,当字段类型为double时,precision表示数值的总长度,scale表示小数点所占的位数。
效果展示:

我只展示了使用多的

dialect参数配置错误会报错:
ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping‘
’
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>provided</scope>
</dependency>
本文详细介绍了在Spring Boot应用中使用JPA时遇到的自动生成错误,并提供了正确的URL配置和实体类注解设置方法,确保DDL-auto更新模式下数据库操作的顺利进行。
2091

被折叠的 条评论
为什么被折叠?



