在 MySQL 数据库中使用 spring boot 的问题

我正在尝试制作一个连接到 MySQL 数据库的 spring boot 项目,但一直出现错误


java.sql.SQLSyntaxErrorException: 表 'db_todo.pg_class' 不存在


db_todo 是我的数据库的名称。我正在使用 MySQL 8.0.17 版。感谢您提前给我的任何帮助。谢谢!


这是我的 POJO


package com.todo.service.todo;


import javax.persistence.*;


@Entity

@Table(name = "todo")

public class Todo {


    @Id

    @GeneratedValue(strategy= GenerationType.AUTO)

    private int id;

    @Column(nullable = false)

    private String title;

    @Column(nullable = false)

    private boolean completed;



    public Todo(int id, String title, boolean completed) {

        this.id = id;

        this.title = title;

        this.completed = completed;

    }


    public Todo(){


    }


    public int getId() {

        return id;

    }


    public String getTitle() {

        return title;

    }


    public boolean isCompleted() {

        return completed;

    }


    public void setId(int id) {

        this.id = id;

    }


    public void setTitle(String title) {

        this.title = title;

    }


    public void setCompleted(boolean completed) {

        this.completed = completed;

    }

}

这是我的 application.properties


spring.jpa.hibernate.ddl-auto=update

spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_todo?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

spring.datasource.username=springuser

spring.datasource.password=ThePassword

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

spring.jpa.show-sql=false

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

我意识到有些事情可能看起来是不必要的(时区等),但它们已经被添加到我以前的错误中,并且不确定为什么。


最后这是我的 POM.xml,因为我正在使用 maven。


白猪掌柜的
浏览 106回答 1
1回答

幕布斯7119047

请尝试使用这些(因为您使用的是 MySql 而不是 PostgreSQL)spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect希望对您有所帮助 :)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java