【发布时间】:2018-07-18 19:59:14
【问题描述】:
我有一个 Spring Boot + Thymeleaf 应用程序和以下工作代码:
控制器:
@Controller
@SessionAttributes( {"myBean"} )
public class MyController() {
@ModelAttribute("myBean")
public MyBean getMyBean() {
return new MyBean();
}
// multiple requests with "myBean"
// ...
@GetMapping("/page1")
public String page1a(@ModelAttribute MyBean myBean) {
// some code
return "page";
}
@PostMapping("/page1")
public String page1b(@ModelAttribute MyBean myBean) {
// some code
return "result";
}
}
Thymeleaf 页面:
...
<form action="#" th:action="@{/page1}" th:object="${myBean}" method="post">
<!-- some fields-->
</form>
...
当我一次只打开一页时,这很好用。不过,我想比较几个 result.html 页面上的结果,所以我需要能够同时处理多个页面。但我只有 1 个“myBean”实例,因此每次都会覆盖这些值。
是否可以有多个“myBean”实例?
【问题讨论】:
标签: spring spring-boot thymeleaf modelattribute