自定义注解
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)public @interface IgnoreProperty {}然后实体类中:public class TarResearch implements Serializable{ @IgnoreProperty private static final long serialVersionUID = 1L; @IgnorePropertyprivate 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(0, 1).toUpperCase() + field[i].getName().substring(1); Method method = userClass.getMethod("get" + fie); Object obj = method.invoke(u); if (obj == null) { sendResponseMsg(response, "数据错误"); return null; } }

浙公网安备 33010602011771号