zoukankan      html  css  js  c++  java
  • 自定义注解

    @Target(ElementType.FIELD)   

    @Retention(RetentionPolicy.RUNTIME)
    public @interface IgnoreProperty {
    }
    然后实体类中:
    public class TarResearch implements Serializable{
     
     @IgnoreProperty
     private static final long serialVersionUID = 1L;
     
     @IgnoreProperty
    private  Integer researchId;
     
     @IgnoreProperty
     private TarUser userId;
     
     private String version;
     
     private String grade;
    ....
       
     
    然后action类中  
    // 验证数据完整性
     
      Class<TarResearch > userClass = TarResearch .class;
     
      Field[] field = userClass.getDeclaredFields();
     
      for (int i = 0; i < field.length; i++) {
     
       if (field[i].getAnnotation(IgnoreProperty.class) != null) {
     
        continue;
     
       }
     
       String fie = field[i].getName().substring(01).toUpperCase()
     
         + field[i].getName().substring(1);
     
       Method method = userClass.getMethod("get" + fie);
     
       Object obj = method.invoke(u);
     
       if (obj == null) {
     
        sendResponseMsg(response, "数据错误");
     
        return null;
     
       }
     
      }
  • 相关阅读:
    File
    多态
    方法重载
    Math
    instanceof
    强制类型转换
    泛型
    springboot热部署
    iOS bug处理
    iOS8-xcode6中添加pch全局引用文件
  • 原文地址:https://www.cnblogs.com/sddychj/p/6760938.html
Copyright © 2011-2022 走看看