我有一个用户实体:
@Entity
@Table(name = "user")
public class User implements Serializable{
private enum Sex {MALE, FEMALE};
@Id @GeneratedValue
private Long id;
@NotNull
private String name;
@NotNull
private String password;
}
控制器:
@Controller
public class HomeController {
@RequestMapping("/addUser")
public String showHomePage(Map<String, Object> map) {
map.put("user", new User());
return "addUser";
}
并在jsp文件中形成
<form:form method="post" action="add" commandName="user">
<form:input path="name"/>
<form:input path="password"/>
<form:input path="confirm-password"/>
</form:form>
此表单会生成错误,因为confirm-password
. User.class
我当然可以添加confirm-password
字段 as @Transient
to User.class
,但是如果我想在我的表单中添加验证码字段怎么办。是否有其他方法可以向表单添加其他字段?