当我使用带有IntelliJ Ultimate IDE的Spring Boot部署Maven项目时,出现错误500,
Wed Jul 10 15:51:03 IST 2019
There was an unexpected error (type=Internal Server Error, status=500).
could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
所以我假设这可能是由于控制器类中的Date参数错误导致的,我按如下方式传递数据,
package com.example.test3.controller;
import com.example.test3.model.employee;
import com.example.test3.repo.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class WebController {
@Autowired
CustomerRepository repository;
@RequestMapping("/save")
public String process(){
// save a single employee
repository.save(new employee("Jack", "ekanayakeindrajith@gmail.com", new Date(2099,9,2), "skill1"));
return "Done";
}
}
日期属性中有一个警告,
'Date(int,int,int)'已弃用
但是,我仍然不知道如何正确配置它。我已经在Stackoverflow中提到了类似的问题
Question2,但仍然无法解决此问题。任何帮助将不胜感激!
编辑:
employee.java
文件如下,
package com.example.test3.model;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "employee")
public class employee implements Serializable {
private static final long serialVersionUID = -3009157732242241606L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "fullname")
private String fullname;
@Column(name = "email")
private String email;
@Column(name = "dateofbirth")
private Date dateofbirth;
@Column(name = "skill")
private String skill;
protected employee() {
}
public employee(String fullname, String email, Date dateofbirth, String skill) {
this.fullname = fullname;
this.email = email;
this.dateofbirth=dateofbirth;
this.skill=skill;
}
@Override
public String toString() {
return String.format("employee[id=%d, fullname='%s', email='%s', dateofbirth='%s', skill='%s']", id, fullname, email, dateofbirth, skill);
}
}