私は thymeleaf を初めて使用します... 誰かが thymeleaf html とスプリングコントローラーの間で値がどのように渡されるか教えてください... thymeleaf-spring-mvc の良いチュートリアルを提案してください...
以下の例では、ユーザーがテキスト フィールドに入力した所有者の値がどのようにスプリング コントローラーに渡され、検証されて結果が返されるかを教えてください。また、逆に、コントローラーによって返された結果が thymeleaf によって取得されて結果が表示される方法.. LASTNAME の値がコントローラーに認識される方法.. コントローラー owner.getLastName(). の所有者オブジェクトに渡される方法..
所有者を探す
<form th:object="${owner}" action="ownersList.html" th:action="@{'/owners.html'}" method="get" class="form-horizontal"
id="search-owner-form">
<fieldset>
<div class="control-group" id="lastName">
<label class="control-label">Last name </label>
<input type="text" th:field="*{lastName}" size="30" maxlength="80"/>
<span class="help-inline" th:errors="*{lastName}">[Errors]</span>
</div>
<div class="form-actions">
<button type="submit">Find Owner</button>
</div>
</fieldset>
</form>
@RequestMapping(value = "/owners", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Model model) {
// allow parameterless GET request for /owners to return all records
if (owner.getLastName() == null) {
owner.setLastName(""); // empty string signifies broadest possible search
}
// find owners by last name
Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName());
if (results.size() < 1) {
// no owners found
result.rejectValue("lastName", "notFound", "not found");
return "owners/findOwners";
}
if (results.size() > 1) {
// multiple owners found
model.addAttribute("selections", results);
return "owners/ownersList";
} else {
// 1 owner found
owner = results.iterator().next();
return "redirect:/owners/" + owner.getId();
}
}