Mongodb Spring boot找不到我的模板视图出现意外错误(类型=未找到,状态=404)
我花了几乎一天的时间试图解决这个问题,但没有任何运气 我正在集成spring boot mongodb和thymeleaf 这是我的控制器Mongodb Spring boot找不到我的模板视图出现意外错误(类型=未找到,状态=404),mongodb,spring-boot,gradle,intellij-idea,thymeleaf,Mongodb,Spring Boot,Gradle,Intellij Idea,Thymeleaf,我花了几乎一天的时间试图解决这个问题,但没有任何运气 我正在集成spring boot mongodb和thymeleaf 这是我的控制器 @Controller public class ItemController { @Autowired private ItemService itemService; @GetMapping("/items") public String home(Model model) { model.addAttribute("items
@Controller
public class ItemController {
@Autowired
private ItemService itemService;
@GetMapping("/items")
public String home(Model model) {
model.addAttribute("items", new ItemEntity());
List<ItemEntity> items = itemService.findAll();
model.addAttribute("items", items);
return "item";
}
}
我也在application.properties中为mongod提供了这些
spring.data.mongodb.database=vending
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
当我运行VendingApplication并转到时,我得到了这个
白标错误页
此应用程序没有/error的显式映射,因此您将其视为回退
美国东部时间2020年2月15日星期六03:26:41
出现意外错误(类型=未找到,状态=404)。
没有可用的消息
由于某种原因,spring似乎无法解析模板视图
更新:
问题来自数据库名,它没有映射到我的数据库名
application.properties
spring.data.mongodb.database=your_db_name
在模板中,您将使用方法作为post
<form action="" th:action="@{'/fileupload'}" th:object="${item}" method="post"
对于曾经关注的人,我的问题来自application.propertiesspring.data.mongodb.database
我必须将它映射到我的文档集合已经尝试过了,帖子是用于文件上传的,我尝试加载前视图,然后当然需要实现帖子控制器。但即使在html中使用get方法,结果仍然相同
application.properties
spring.data.mongodb.database=your_db_name
<form action="" th:action="@{'/fileupload'}" th:object="${item}" method="post"
<form action="" th:action="@{'/fileupload'}" th:object="${item}" method="get"