Spring Boot @Entity table在mysql中没有生成

gcuhipw9  于 2023-05-17  发布在  Spring
关注(0)|答案(1)|浏览(111)

在运行项目之后,难道不应该在我的数据库中自动生成用户表吗?我在运行服务器后也刷新了它,但是用户表没有显示在mysql中。
application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/BloggingApp
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto = create
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace

用户类

package com.example.entities;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String name;
    private String email;
    private String password;
    private String about;
}

主要

package com.example.blogging.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@SpringBootApplication
@EnableConfigurationProperties
@EntityScan
public class BloggingAppApplication {

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

}

项目结构:

6tdlim6h

6tdlim6h1#

由于您的实体包与Sping Boot 主类不同,因此必须在@EntityScan中指定包

@EntityScan("com.example.entities.*")

相关问题