gpt4 book ai didi

java - Spring Boot 应用程序中的 MySQL 数据库中没有创建表

转载 作者:行者123 更新时间:2023-11-28 23:16:05 25 4
gpt4 key购买 nike

这是我的 Application.java:

@Configuration
@EnableAutoConfiguration(exclude =
{JpaRepositoriesAutoConfiguration.class})
@ComponentScan
@SpringBootApplication
public class UserFrontApplication {

public static void main(String[] args) {
SpringApplication.run(UserFrontApplication.class, args);
}
}

application.properties 的内容:

spring.datasource.driverClassName=org.gjt.mm.mysql.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=password

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

pom.xml:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.userFront</groupId>
<artifactId>userfront</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>UserFront</name>
<description>User frontend for online banking</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

应用程序运行正常,但没有创建表。

必须存储在数据库中的用户类:

@Entity
@Table(name = "user")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "userId", nullable = false, updatable = false)
private Long userId;
}

最佳答案

为什么使用 org.hibernate.dialect.PostgreSQLDialect。您需要根据您的数据库更新方言,更新这两个属性。

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

关于java - Spring Boot 应用程序中的 MySQL 数据库中没有创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com