我有我的DTO,要在其中分配来自form:option标签的列表中的对象。 DTO
public class UserDTO implements Serializable {
private Group group;
@JsonProperty("phone")
private String phone;
@JsonProperty("password")
private String password;
@JsonProperty("confirmPassword")
private String confirmPassword;
-- Getters and setters
}
JSP
<spring:bind path="group">
<div class="form-group inner-addon left-addon ${status.error ? 'has-error' : ''}">
<form:select path="group" class="form-control">
<c:forEach items="${groups}" var="group">
<form:option value="${group}" label="${group.name}"/>
</c:forEach>
</form:select>
<form:errors path="group"/>
</div>
</spring:bind>
控制器
@RequestMapping(value = "/finish-registration", method = RequestMethod.GET)
public String finishRegistration(Model model) {
model.addAttribute("groups", GROUP_LIST);
model.addAttribute("UserDTO", new UserDTO());
return "finish-registration";
}
@RequestMapping(value = "/finish-registration", method = RequestMethod.POST)
public String finishRegister(@ModelAttribute("UserDTO") UserDTO userDTO, BindingResult result, Model model, Locale locale) {
System.out.println(userDTO.toString());
studentValidator.validate(userDTO, result);
if (result.hasErrors()) {
return "finish-registration";
}
}
结果我有错误
Caused by: javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String
我不明白为什么值没有作为对象映射到DTO字段。