【发布时间】:2019-08-23 07:53:38
【问题描述】:
我使用 Spring Data JPA 在 MySQL 中创建表,但是创建失败。在我的实体类中找不到错误,我认为配置没有错。
我修改了属性中的一些jdbc连接语句,以及实体类上的注解,但是没有用。
@Data
@Entity
@Table
public class User {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@Column(unique = true)
private String userName;
@Column
private String password;
}
属性文件如下:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/blog?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=localhost # Spring Data Jpa
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
【问题讨论】:
-
控制台是否有任何错误或异常?你能提供连接细节吗?
-
# MySQL spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/blog?characterEncoding=utf8&useSSL =false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=localhost # Spring Data Jpa spring.jpa.hibernate.ddl-auto=create spring.jpa.show-sql=true
-
这是我的属性文件
-
varchar如何自动递增?我建议您将其更改为例如integer。 -
@SudhirOjha 破折号分隔的属性对于 Spring Boot 是正确的,是骆驼大小写变体的替代方案。
标签: java spring-boot jdbc spring-data-jpa