我有傳遞ARGS從HTML麻煩使用thymeleaf 3.傳遞參數與thymeleaf
這裏Spring MVC的控制器4彈簧控制器,所述控制器:
// Handler method for inserting currency:
@RequestMapping(value = "/saveCurrency", method = RequestMethod.POST)
public ModelAndView saveCurrency(@ModelAttribute("currency") Currency currency, BindingResult bindingResult, Model model)
{
model.addAttribute("currency", currency);
currDAO.insert(currency);
return new ModelAndView("redirect:/listCurr");
}
和HTML形式:
<form action="/saveCurrency" th:action="@{/saveCurrency}" th:object="${currency}" th:method="post">
<input id="nameTB" type="text" th:field="*{name}" class="form-control" maxlength="3" style="text-transform:uppercase" />
...
</form>
我也有班級「ID」和「名稱」,並與他們的getter和setter類貨幣。 現在有了這個代碼,我得到一個錯誤:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/listCurr.html]")] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'currency' available as request attribute
任何想法,我究竟做錯了什麼?
我得到相同的錯誤... – CoffeePen