【发布时间】:2020-03-12 09:20:27
【问题描述】:
专家,
我正在努力从 Themeleaf 调用控制器。
我的主题代码如下:
<form action="#" th:action="@{/order}" modelAttribute="order" th:object="${order}" method="POST">
<div class="div">
<h5>Amount</h5>
<input type="text" class="input" th:field="*{amountValue}">
</div>
<input type="submit" class="btn" value="Process Payment">
</form>
我的控制器代码是:
@RequestMapping(value = "/order", method = RequestMethod.POST)
public ModelAndView processOrder(@ModelAttribute Order order) {
ModelAndView modelAndView = new ModelAndView();
String accessToken = token();
String paymentURL = null;
if (accessToken != null) {
paymentURL = placeOrder(accessToken, order);
if (paymentURL != null) {
modelAndView.addObject("orderReferenceNumber", paymentURL.substring(paymentURL.indexOf("=") + 1));
modelAndView.addObject("paymentURL", paymentURL + "&slim=true");
modelAndView.setViewName("paymentProcess");
return modelAndView;
}
}
return modelAndView;
}
我的 Get 方法是
@RequestMapping(value = "/index", method = RequestMethod.POST)
public ModelAndView doLogin(@RequestParam(value = "username", required = true) String username,
@RequestParam(value = "password", required = true) String password) {
ModelAndView modelAndView = new ModelAndView();
if (username != null && password != null) {
if (username.equalsIgnoreCase("one") && password.equalsIgnoreCase("one")) {
modelAndView.addObject("order", new Order());
modelAndView.setViewName("index");
return modelAndView;
}
}
modelAndView.setViewName("welcome");
return modelAndView;
}
点击按钮出错
Error resolving template [order], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [order], template might not exist or might not be accessible by any of the configured Template Resolvers
我做错了什么?
【问题讨论】:
-
能否请您添加返回包含此表单的初始视图的 GET 控制器方法?
标签: spring spring-boot spring-mvc spring-data-jpa