java - IntelliJ 中的 Thymeleaf 无法解析变量
问题描述
我正在 IntelliJ 上使用 Spring Boot 和 Thymeleaf 编写一个简短的 Web 表单应用程序,但似乎在 HTML 文件中,模型中的所有字段都无法解析。这是我的代码:
这是样板酒店的代码:
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
private String nomHotel;
private String ville;
private String description;
private String image;
@OneToMany (mappedBy = "hotel", fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
List<voyageOrg> vo;
@OneToMany (mappedBy = "hotels", fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
List<reservation> res;
}
控制器类:
@Controller
public class HotelController {
@Autowired
private HotelService hotelService;
@GetMapping("/listHotel")
public String listHotel(){
return "hotels";
}
public String hotel (Model model){
model.addAttribute("listHotel",hotelService.getAllHotels());
return "hotels";
}
}
查看文件:
<tbody>
<tr th:each="hotel:${listHotel}"></tr>
<td th:text="${hotel.nomHotel}"></td>
<td th:text="${hotel.ville}"></td>
</tbody>
, listHotel
, hotel
,用nomHotel
红色ville
下划线标有“无法解决”。
解决方案
推荐阅读
- excel - 是否可以打开文件资源管理器并单击文本文件以获取 VBA 中的地址名称?
- r - 在自动绘图中更改颜色和框架
- firebase - Cloud Firestore 文档数据库中的正确设计
- r - 在 r 中查找具有相同开口的字符串
- django - 在 request.POST 之后留在同一个 django 模板中
- javascript - 单击链接后如何自动关闭响应式导航?
- sql - (SQL) 如何根据使用 OVER 计算的值进行条件过滤
- azure - 将 Azure 设置为在服务器崩溃时自动重启
- sql - 检索表中的层次结构
- laravel-5 - Laravel Echo + Redis + Socket.io