我是百老汇的新手......有人可以告诉你百事可乐和弹簧控制器之间的价值观是如何传递的......请为thymeleaf-spring-mvc建议好的教程......
在下面的示例中,请让我知道用户在文本字段中输入所有者的值是如何传递给spring控制器的,以便验证并返回结果。反之,控制器返回的结果如何由百万美元来显示结果。如何知道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();
}
}
答案 0 :(得分:1)
假设您有一个控制器方法,如:
void method-name(Owner owner){
// ...
}
单击提交按钮时,值会自动设置为域类,然后创建新方法并设置对象的模型属性
model.addAttribute("owner",new Owner)
;