【发布时间】:2019-12-07 20:06:05
【问题描述】:
我已将模型属性“authRequest”从控制器传递到“dashboard.html”。从“dashboard.html”我想在单击“查看卡片”按钮时调用另一个服务。还想将modelAttribute“authRequest”传递回视图卡控制器,以便我将在“viewCards.html”中获取modelAttribute“authRequest”。我尝试给出 th:href 和 form-action 但无法在视图卡控制器中获得“authRequest”的值,因此无法在“viewCards.html”中获得。如何将modelAttribute“authRequest”传递给viewCards控制器? 尝试如下传递modelAttribute
<form action="#" th:action="@{/viewCards}" th:object="${authRequest}" method="post">
<input type="submit" value="View cards" /></form>
也试过href
<a th:href="@{/viewCards}" th:object="${authRequest}">view Cards</a>
dashboard.html - 在这里我可以获得 ${authRequest.userName}" 的价值
<form action="#" th:action="@{/viewCards}" th:object="${authRequest}" method="post">
<input type="submit" value="View cards" />
</form>
<p th:text="'User Name: ' + ${authRequest.userName}" />
viewCards.html - 无法获取 ${authRequest.userName} 的值
<script type="text/javascript" th:src="@{/webjars/jquery/1.9.1/jquery.min.js/}"></script>
<script th:inline="javascript">
var user= [[${authRequest.userName}]];
</script>
<script type="text/javascript" th:src="@{/vCards.js}"></script>
<p th:text="'User Name: ' + ${authRequest.userName}" />
控制器
@RequestMapping(value= "/virtualWallet/login" , method= RequestMethod.POST)
public String getAuthResponse(
@ModelAttribute AuthRequest authRequest,
Model model
){
String resp = authService.getAuthResponse(authRequest);
if(resp.equals("Success")) {
return "dashboard";
}
return null;
}
@RequestMapping(value= "/viewCards" , method = RequestMethod.POST)
public String viewCards(
@ModelAttribute AuthRequest authRequest
) {
return "viewCards";}
预计会在“viewCards.html”中获得“authRequest”值。我要空了。
【问题讨论】:
标签: jquery spring-boot thymeleaf