Validations:struts2注解方式校验
? ? ? ?用注解的方式,实现struts2的validations ? 一个小demo段:
? ? ? ?
? ? ? ?@Validations(
? ? ? ? ? ?requiredStrings={
? ? ? ? ? ? ? ? ?@RequiredStringValidator(fieldName="user.name",message="用户不能名为空")
? ? ? ? ? ?}
? ? ? )
? ? ? @InputConfig(resultName="error")
? ? ? public String save(){
? ? ? ? ? ? if(user.getName().equals("caixen")){
? ? ? ? ? ? ? ? addActionError("不能使用该名字");
? ? ? ? ? ? ? ? return "error";
? ? ? ? ? ?}else if(user.getName().equals("cc")){
? ? ? ? ? ? ? ?addActionError("名字不可用!");
? ? ? ? ? ? ? ?return "error";
? ? ? ? ? }
? ? ? ? ?return "save";
? ? }
actionp配置文件中添加“error”的返回处理结果
?
?