问题描述
目前,我正在学习Thymeleaf。我想向用户展示简单的网格包含按钮和值。问题是我无法在迭代期间访问Java对象的变量。 2d数组由SeatsSeances对象组成。
ERROR in Module build Failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined variable.
╷
│ background-color: $primary;
│ ^^^^^^^^
╵
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class SeatsSeance {
private Integer id;
private Integer seatId;
private Integer seanceId;
private SeatState state;
}
当我只是尝试<table>
<tr th:each="row: ${seatSeances}">
<td th:each="place: ${row}">
<input type="button" th:text="${place.state.name()}"> //not working
<input type="button" th:text="${place.getState().name()}"> //not working
</td>
</tr>
</table>
时,会出现错误:
th:text="${place.state.name()}"
我做错了什么? Thu Aug 20 09:38:54 CEST 2020
There was an unexpected error (type=Internal Server Error,status=500).
An error happened during template parsing (template: "class path resource [templates/buyticket.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/buyticket.html]")
标记内应该有什么?
已更新1
SeatSeance类:
<td th:each>
SeatState类
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class SeatsSeance {
private Integer id;
private Integer seatId;
private Integer seanceId;
private SeatState state;
}
IDE允许我使用HTML中的所有字段,因此问题不在于可访问性。而且,使用没有问题
public enum SeatState { RESERVED,ORDERED,FREE
}
当我想显示对象的一个字段时,问题就开始了。尽管有getter和setter方法,我还是无法做到这一点
更新2
解决方法
您必须为课程的所有属性提供getter / setter。如果您使用Spring Lombok,则需要添加@Getter @Setter
标签。