在Spring Boot应用程序(Java 8)的控制器中设置日期值

在Spring Boot应用程序(Java 8)的控制器中设置日期值,java,spring-boot,api,gradle,java-8,Java,Spring Boot,Api,Gradle,Java 8,在我的模型中,我有以下内容: private Date exampleDate; public Testing(Date exampleDate) { this.exampleDate = exampleDate; } public Date getExampleDate() { return (Date) this.exampleDate.clone(); } public void setExampleDate(Date exam

在我的模型中,我有以下内容:

private Date exampleDate;

public Testing(Date exampleDate) {
        this.exampleDate = exampleDate;
    }

public Date getExampleDate() {
        return (Date) this.exampleDate.clone();
    }

    public void setExampleDate(Date exampleDate) {
        this.exampleDate = (Date) exampleDate.clone();
    }
我试图输出一个对象数组,如下所示

@RestController
public class TestingController {
    @GetMapping("/saved")
    public List<Testing> getData() {
        List<Testing> savedDatas = new ArrayList<>(Arrays.asList(
                new Testing(
                        1,
                        "Text",
                        2000-1- 1),
                new Testing(
                        2,
                        "Text2",
                        new Date(27 / 03 / 19)),
@RestController
公共类测试控制器{
@GetMapping(“/saved”)
公共列表getData(){
List savedDatas=new ArrayList(Arrays.asList(
新测试(
1.
“文本”,
2000-1- 1),
新测试(
2.
“文本2”,
新日期(19年3月27日),

我尝试使用new Date,但这不起作用,所以我需要以type
Date
而不是String或int作为第三个参数传递什么?!

我建议您使用较新的类:

LocalDateTime

然后,您可以使用静态工厂方法获取LocalDateTime实例:

LocalDateTime.of(date, time); //or
LocalDate.of(date);

“代码>日期>代码>来自什么?是代码吗?java?UTIL.DATE < /COD>?@尼科拉斯是……当你使用java 8时,请不要使用20岁的旧代码< java > UTIL.DATE <代码>。使用<代码> java。时间。LoalDead < /C> >你的问题不清楚。PLZ共享什么异常?考虑使用<代码> LoalDead < /C> >代码>LocalDateTime而不是作为。
LocalDateTime.of(date, time); //or
LocalDate.of(date);