问题描述
我正在使用 spring boot 为应用程序easy-notes制作一个rest api。但是我在 eclipse ide 上运行它时遇到了一些错误。我的项目的链接是:https://drive.google.com/drive/folders/1RnyZI9r9l5IVHtUT1j1N5p2krRqcvDUw?usp=sharing
作为参考,这是控制台日志的链接:https://drive.google.com/file/d/1_kWy9SSomF75dKqTdd2lG3zgwKJkmiJO/view?usp=sharing
解决方法
您的代码有几个问题首先进行以下更改 在您的 application.properties 文件中更改
apring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
到
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
然后你在这里建模https://drive.google.com/drive/folders/1RMpFXCUIhkFpcH8vreAnbdPHJgs1_tCl
改变
public class Note {
@Entity
@Table(name = "courses")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt","updatedAt"},allowGetters = true)
public class note implements Serializable {
...
到
@Entity
@Table(name = "courses")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt",allowGetters = true)
public class Note implements Serializable {
...
所以完整正确的文件如下:
package com.hp.easynotes.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "courses")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt",allowGetters = true)
public class Note implements Serializable {
@Id
@GeneratedValue
private Long id;
private String title;
private String content;
@Column(nullable = false,updatable = false)
@Temporal(TemporalType.TIMESTAMP)
@CreatedDate
private Date CreatedAt;
@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
@LastModifiedDate
private Date UpdatedAt;
//Getters & Setters
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getCreatedAt() {
return CreatedAt;
}
public void setCreatedAt(Date createdAt) {
CreatedAt = createdAt;
}
public Date getUpdatedAt() {
return UpdatedAt;
}
public void setUpdatedAt(Date updatedAt) {
UpdatedAt = updatedAt;
}
}