首页 > 解决方案 > 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下划线标有“无法解决”。

标签: javaspring-bootspring-mvcspring-securitythymeleaf

解决方案


推荐阅读