Spring boot 对SpringEL表达式求值时出现异常:“0”;日期“a”;在其他3页上工作的代码上

Spring boot 对SpringEL表达式求值时出现异常:“0”;日期“a”;在其他3页上工作的代码上,spring-boot,thymeleaf,modelattribute,Spring Boot,Thymeleaf,Modelattribute,我有这个代码的问题 <form action="#" th:action="@{'/portfolio/' + ${portfolios.getId()} + '/old' }" th:object="${Date}" method="post"> <table> <tr> <td>From: <input type="date" th:value="*{date_a}" th:field="*{date_a}" /&

我有这个代码的问题

<form action="#" th:action="@{'/portfolio/' + ${portfolios.getId()} + '/old' }" th:object="${Date}" method="post">
<table>
    <tr>
        <td>From: <input type="date" th:value="*{date_a}" th:field="*{date_a}" /></td>
    </tr>
    <tr>
        <td><input type="submit" th:onclick="'javascript:loading()'" value="Change day" /></td>
    </tr>
</table>
我在上一页传递了一个空对象

ThymeDate date = new ThymeDate();
modelAndView.addObject("Date", date);
编辑:

百里香酸盐

@Entity
 @Table(name = "dto_thyme")
 public class ThymeDate implements Serializable {

@Id
@GeneratedValue
long id;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date_a;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date_b;

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public LocalDate getDate_a() {
    return date_a;
}

public void setDate_a(LocalDate date_a) {
    this.date_a = date_a;
}

public LocalDate getDate_b() {
    return date_b;
}

public void setDate_b(LocalDate date_b) {
    this.date_b = date_b;
}

public ThymeDate() {

}

public ThymeDate(LocalDate date_a, LocalDate date_b) {

    this.date_a = date_a;
    this.date_b = date_b;
}

}我还是不知道这是不是关于保留关键字之类的。。。 将表单对象名称从Date更改为ThymleDate,现在可以使用了吗


如果有人有更好的解释,我可以接受作为答案…

请您在问题中添加ThymleDate类片段。类中必须有一个公共getter“getDate_a()”才能在template.added中使用“*{date_a}”。它也适用于其他页面,所以这不是问题所在。您可以在表单元素之前使用类似于

的内容检查您的模型。也许这里发生了什么事。另外,我不知道thymeleaf是否会像前面所说的那样绑定一个未设置的LocalDate-field。它在其他页面上工作,所以我认为绑定空对象不是问题。此外,Date.Date_a为空,Date按预期打印出对象类型
@Entity
 @Table(name = "dto_thyme")
 public class ThymeDate implements Serializable {

@Id
@GeneratedValue
long id;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date_a;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate date_b;

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public LocalDate getDate_a() {
    return date_a;
}

public void setDate_a(LocalDate date_a) {
    this.date_a = date_a;
}

public LocalDate getDate_b() {
    return date_b;
}

public void setDate_b(LocalDate date_b) {
    this.date_b = date_b;
}

public ThymeDate() {

}

public ThymeDate(LocalDate date_a, LocalDate date_b) {

    this.date_a = date_a;
    this.date_b = date_b;
}