Java 未从Spring boot JPA在mysql架构中创建表

Java 未从Spring boot JPA在mysql架构中创建表,java,mysql,spring,spring-boot,Java,Mysql,Spring,Spring Boot,我正在创建一个SpringBoot应用程序,并尝试与mysql数据库建立连接 我已经创建了一个模式。并尝试通过SpringBootJPA在表中添加列 即使我的身材已经通过了测试,我也无法获得成功。我已经尝试了所有可能的方法从堆叠流,但没有运气 这是我的应用程序。属性 spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false spring.datasource.username

我正在创建一个SpringBoot应用程序,并尝试与mysql数据库建立连接

我已经创建了一个模式。并尝试通过SpringBootJPA在表中添加列

即使我的身材已经通过了测试,我也无法获得成功。我已经尝试了所有可能的方法从堆叠流,但没有运气

这是我的
应用程序。属性

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?useSSL=false
spring.datasource.username=root
spring.datasource.password=root

spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto= update
这是我的模型课

package com.springboot.Model;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "employees")

public class Employee {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    @Column(name = "first_name")
    private String  fristName;
    
    @Column(name = "last_name")
    private String lastName;
    
    @Column(name = "email_id")
    private String emailId;
    
    public Employee() {
        
    }
    
    public Employee(String fristName, String lastName, String emailId) {
        super();
        this.fristName = fristName;
        this.lastName = lastName;
        this.emailId = emailId;
    }
    
    
    public long getId() {
        return id;
    }
    
    public void setId(long id) {
        this.id = id;
    }
    
    public String getFristName() {
        return fristName;
    }
    
    
    public void setFristName(String fristName) {
        this.fristName = fristName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmailId() {
        return emailId;
    }
    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }
}
生成日志:

我对我的db连接也有疑问。调试或查找spring是否命中模式的方法是什么


有人能帮我吗。这是我的第一个Spring java应用程序。

需要在数据源URL中添加
createDatabaseIfNotExist=true
参数,如下例所示:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?createDatabaseIfNotExist=true&useSSL=false

需要在数据源URL中添加
createDatabaseIfNotExist=true
参数,如下例所示:

spring.datasource.url=jdbc:mysql://localhost:3306/employee_management_system?createDatabaseIfNotExist=true&useSSL=false
  • 您确定您的
    实体
    基本包或基本包的子包下吗?如果没有,则需要将其添加到主应用程序文件中的
    Scan

    @EntityScan(basePackages = {"com.springboot.Model"}) 
    
  • 请尝试以下属性:

    spring.jpa.generate-ddl=true <br>
    spring.jpa.hibernate.ddl-auto=create
    
    spring.jpa.generate ddl=true
    spring.jpa.hibernate.ddl auto=create
  • 您确定您的
    实体
    基本包或基本包的子包下吗?如果没有,则需要将其添加到主应用程序文件中的
    Scan

    @EntityScan(basePackages = {"com.springboot.Model"}) 
    
  • 请尝试以下属性:

    spring.jpa.generate-ddl=true <br>
    spring.jpa.hibernate.ddl-auto=create
    
    spring.jpa.generate ddl=true
    spring.jpa.hibernate.ddl auto=create

  • 您的日志包含一个警告。请与我们共享完整的警告消息好吗?@pcsutar“spring.jpa.open-in-view在默认情况下处于启用状态。因此,在视图呈现过程中可能会执行数据库查询。显式配置spring.jpa.open-in-view以禁用此警告“@pcsutar I have update in comment”。请检查。您的日志包含一条警告。请与我们共享完整的警告消息好吗?@pcsutar“spring.jpa.open-in-view在默认情况下处于启用状态。因此,在视图呈现过程中可能会执行数据库查询。显式配置spring.jpa.open-in-view以禁用此警告“@pcsutar I have update in comment”。请核对。我想在这里补充两件事。1:数据库已存在。2.如果我给数据库起了一个新名字,比如
    spring.datasource.url=jdbc:mysql://localhost:3306/new_database?createDatabaseIfNotExist=true&useSSL=false
    正在创建数据库,但表中仍缺少列。但我们现在确定数据库连接已经建立。您的主类是否驻留在
    com.springboot.Model
    com.springboot
    包中?是的,正如@Tarun建议的那样,我移动了类,它现在工作了。谢谢,我想在这里补充两件事。1:数据库已存在。2.如果我给数据库起了一个新名字,比如
    spring.datasource.url=jdbc:mysql://localhost:3306/new_database?createDatabaseIfNotExist=true&useSSL=false
    正在创建数据库,但表中仍缺少列。但我们现在确定数据库连接已经建立。您的主类是否驻留在
    com.springboot.Model
    com.springboot
    包中?是的,正如@Tarun建议的那样,我移动了类,它现在工作了。谢谢你。实际上所有包都不在基本包之下。它可以工作。实际所有包不在基本包下。