为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

白猪掌柜的 2023-05-10 14:15:56
我正在尝试制作一个连接到 MySQL 数据库的 spring boot 项目,但一直出现错误java.sql.SQLSyntaxErrorException: 表 'db_todo.pg_class' 不存在db_todo 是我的数据库的名称。我正在使用 MySQL 8.0.17 版。感谢您提前给我的任何帮助。谢谢!这是我的 POJOpackage 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.propertiesspring.jpa.hibernate.ddl-auto=updatespring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_todo?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTCspring.datasource.username=springuserspring.datasource.password=ThePasswordspring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialectspring.jpa.show-sql=falsespring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl我意识到有些事情可能看起来是不必要的(时区等),但它们已经被添加到我以前的错误中,并且不确定为什么。最后这是我的 POM.xml,因为我正在使用 maven。
查看完整描述

1 回答

?
幕布斯7119047

TA贡献1794条经验 获得超8个赞

请尝试使用这些(因为您使用的是 MySql 而不是 PostgreSQL)

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

希望对您有所帮助 :)


查看完整回答
反对 回复 2023-05-10
  • 1 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信