`
kxhu
  • 浏览: 86227 次
社区版块
存档分类
最新评论

validate with annotation

 
阅读更多
setp
1:define
    @Retention(RetentionPolicy.RUNTIME)
    public @interface RequestValidate {
        RequestValidateItem[] value();
    }

    @Retention(RetentionPolicy.RUNTIME)
    public @interface RequestValidateItem {
        public String parameter() default "";
        public static final String TYPE_DOUBLE = "#DOUBLE";
    }
2:use point
    @RequestValidate({
        @RequestValidateItem(parameter="createTime",required=true,caption="创建时间",msg="不能为空",type=RequestValidateItem.TYPE_DATE),
        @RequestValidateItem(parameter="endTime",required=true,caption="创建时间",msg="不能为空",type=RequestValidateItem.TYPE_DATE)
    })
3:proccess logic
            targetMethod = this.getClass().getMethod(targetMethodName);
            if (targetMethod.isAnnotationPresent(RequestValidate.class)) {
                StringBuffer retObjMsg = new StringBuffer();
                Annotation[] annotations = targetMethod.getAnnotations();
                for (Annotation annotation : annotations) {
                    if (annotation instanceof RequestValidate) {
                        RequestValidate rv = (RequestValidate) annotation;
                        for(RequestValidateItem rvi : rv.value()){
                            String retValidate = validate(rvi);//detail logic
                            if (null != retValidate) {
                                retObjMsg.append(retValidate + "   ");
                            }
                        }
                    }
                if (retObjMsg.length() > 0)
                    return createMsgBox(retObjMsg.toString());
            }
            retObj = targetMethod.invoke(this);


test method:use po test annotation
    1:new plugmodule:<property name="autoRegisterComponent" value="true"/>
    2:new DemoPO extends StatePresentationObject
    3:<service-using
            serviceUuid="hippo.plugmodule.services.presentation"
            description="注册必要的入口页面">
            <WebPresentation namespace="hkx"
                autoRegisterResource="true" autoRegisterPO="true"
                presentationObjectPackage="com.woaika.framework.test.hkx.prez">
            </WebPresentation>
    </service-using>
分享到:
评论

相关推荐

    Devart LinqConnect 3.1

    The behaviour is changed: the Validate Max Length attribute is synchronized with the Max Length attribute of Property by default now The behaviour is changed: the Validate Required attribute is ...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    handling capabilities, and the use of assertions to validate the expected behavior of code. &lt;br&gt;Chapter 13Strings and Regular Expressionsdescribes the built-in language and runtime support for ...

    django-1.3-cheetsheet

    #### 二、聚合与注释函数(Aggregation/Annotation Functions) 聚合与注释函数可以用来对查询结果进行计算和统计。 1. **`Avg(field)`**:计算指定字段的平均值。 - 示例:`Customer.objects.all().aggregate...

    restfulapi:restfulapi实践

    import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/users") public class UserController { @GetMapping("/{id}") public User getUser(@PathVariable Long id) { // ...

Global site tag (gtag.js) - Google Analytics