@GetMapping("/add_rooms") public void addRoom(@RequestParam("roomname") String roomName, @RequestParam("roomaddress") String roomAddress, @RequestParam("roomtype") String roomType, @RequestParam("roomfood") String roomFood, @RequestParam("roomwifi") int roomWifi, @RequestParam("roomprice") Float roomPrice) { Room room = new Room(); room.setR_name(roomName); room.setR_type(roomType); room.setR_food(roomFood); room.setR_wifi(roomWifi); room.setR_price(roomPrice); System.out.println(room.getR_name()); // if(roomService.addRoom(room)){ // System.out.println("成功"); // }else{ // System.out.println("失败"); // } }报错2023-07-07T09:52:18.960+08:00 ERROR 3960 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "add_rooms": Error resolving template [add_rooms], template might not exist or might not be accessible by any of the configured Template Resolvers
时间: 2024-04-07 21:33:15 浏览: 117
Spring@mvc.rar_java 注解_spring mvc
根据你提供的代码和错误信息,问题应该出现在模板引擎尝试渲染名为 "add_rooms" 的模板时。但是根据代码看来,这个方法是一个 `void` 类型的方法,没有返回任何模板。所以模板引擎无法找到对应的模板文件。
解决这个问题的办法是将方法的返回类型改为 `String` 类型,并返回一个要渲染的模板名称。例如:
```java
@GetMapping("/add_rooms")
public String addRoom(@RequestParam("roomname") String roomName,
@RequestParam("roomaddress") String roomAddress,
@RequestParam("roomtype") String roomType,
@RequestParam("roomfood") String roomFood,
@RequestParam("roomwifi") int roomWifi,
@RequestParam("roomprice") Float roomPrice) {
Room room = new Room();
room.setR_name(roomName);
room.setR_type(roomType);
room.setR_food(roomFood);
room.setR_wifi(roomWifi);
room.setR_price(roomPrice);
System.out.println(room.getR_name());
// 执行其他逻辑
return "add_rooms"; // 返回要渲染的模板名称
}
```
在这个示例中,将方法的返回类型改为 `String`,并返回了要渲染的模板名称 "add_rooms"。这样模板引擎就能够正确地解析并渲染该模板了。
请注意,你需要根据你的实际需求修改方法中的逻辑,并确保模板文件 "add_rooms" 存在并且配置正确。
阅读全文