java Sping Boot 不会自动创建mysql数据库表[已关闭]

fnvucqvd  于 2023-01-01  发布在  Java
关注(0)|答案(1)|浏览(90)

这个问题似乎与help center中定义的范围内的编程无关。
4小时前关门了。
Improve this question
人员类别:

package com.skincarebackend.model;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "persons")
public class Person implements Serializable {
    @Id
    @Column(name = "name")
    private String name;

    @Column(name = "surname")
    private String surname;

//    @Column(name = "dob")
//    private Date dob;

    @Column(name = "mobile_no")
    private int mobileNo;

    @Column(name = "gender")
    private String gender;

    public Person(String name, String surname, int mobileNo, String gender) {
        this.name = name;
        this.surname = surname;
//        this.dob = dob;
        this.mobileNo = mobileNo;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

//    public Date getDob() {
//        return dob;
//    }
//
//    public void setDob(Date dob) {
//        this.dob = dob;
//    }

    public int getMobileNo() {
        return mobileNo;
    }

    public void setMobileNo(int mobileNo) {
        this.mobileNo = mobileNo;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return  "Name - " + name + " | Surname - " + surname + " | Mobile No - " + mobileNo + " | Gender - " + gender;
    }
}

我的个人存储库:

package com.skincarebackend.repository;
import com.skincarebackend.model.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PersonRepository extends JpaRepository<Person, Integer> {
    // define any custom repository methods here
}

My application.properties:

#configuration
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/fullstack
spring.datasource.username=root
spring.datasource.password=

#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=false 
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.defer-datasource-initialization=true

以及pom. xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>skincare-backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>skincare-backend</name>
    <description>skincare-backend</description>
    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>3.0.0</version>
        </dependency>

    </dependencies>

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

</project>

控制台:

2022-12-31T01:30:01.830+05:30  INFO 11941 --- [           main] c.s.WestminsterSkinConsultationManager   : Starting WestminsterSkinConsultationManager using Java 17.0.1 with PID 11941 (/Users/sachithyarivisara/Downloads/skincare-backend/target/classes started by sachithyarivisara in /Users/sachithyarivisara/Downloads/skincare-backend)
2022-12-31T01:30:01.832+05:30  INFO 11941 --- [           main] c.s.WestminsterSkinConsultationManager   : No active profile set, falling back to 1 default profile: "default"
2022-12-31T01:30:02.543+05:30  INFO 11941 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-31T01:30:02.554+05:30  INFO 11941 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-31T01:30:02.554+05:30  INFO 11941 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.4]
2022-12-31T01:30:02.625+05:30  INFO 11941 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-31T01:30:02.625+05:30  INFO 11941 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 755 ms
2022-12-31T01:30:02.928+05:30  INFO 11941 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-31T01:30:02.935+05:30  INFO 11941 --- [           main] c.s.WestminsterSkinConsultationManager   : Started WestminsterSkinConsultationManager in 1.376 seconds (process running for 1.868)

tomcat已启动并正在运行,但未创建表..

bd1hkmkf

bd1hkmkf1#

请将此属性添加到application.properties文件中,然后重试。

spring.jpa.generate-ddl=true

相关问题