网络网站制作过程,做的页面好看的网站,做网站为职业生存不下去,佛山市新城开发建设有限公司网站声明jpa批注处理器因此#xff0c;当您仅可以注释Java类时#xff0c;使用JPA#xff0c;Hibernate或EBeans很酷#xff0c;但是您不是一直希望可以从代码“生成”数据模型的文档吗#xff1f; 提取JPA / Hibernate和其他验证注释的信息#xff1f; 假设您的bean中具有所… 声明jpa批注处理器 因此当您仅可以注释Java类时使用JPAHibernate或EBeans很酷但是您不是一直希望可以从代码“生成”数据模型的文档吗 提取JPA / Hibernate和其他验证注释的信息 假设您的bean中具有所有这些漂亮的注释 Entity
Table(name project_bills)
public class Bill extends Model {private static final long serialVersionUID 1L;IdColumn(namePBI_ID)public Long id;DoubleFormatColumn(namePBI_BILL_AMOUNT,length22)public Double billAmount;Column(namePBI_BILL_DATE)DateTime(patterndd.MM.yyyy)public Date billDate;Column(namePBI_BILL_NUMBER,length10)public String billNumber;Column(namePBI_CAN_BILL)public Boolean canBill;Column(namePBI_COMMENT,length65535)public String comment;Column(namePBI_PAID_DATE)DateTime(patterndd.MM.yyyy)public Date paidDate; 这是如何完成该任务的示例 public static String listEntities(String _package) {StringBuffer retval new StringBuffer();Reflections reflections new Reflections(_package, Play.application().classloader());SetClass? classes reflections.getTypesAnnotatedWith(javax.persistence.Entity.class);for (Class c : classes) {retval.append(c.getName() \n);retval.append(listAnnotations(c.getName()) \n\n);retval.append(listAttributes(c.getName()) \n\n);}return retval.toString();}public static String listAnnotations(String _class) {StringBuffer retval new StringBuffer();try {Annotation[] annotations Class.forName(_class).getAnnotations();if (annotations.length ! 0) {for (int j 0; j annotations.length; j) {retval.append(annotations[j].toString() : annotations[j].annotationType() \n);}retval.append(\n);}} catch (ClassNotFoundException e) {System.out.println(e.toString());return retval.toString();}return retval.toString();}public static String listAttributes(String _class) {StringBuffer retval2 new StringBuffer();boolean perstistent false;try {for (Field field : Class.forName(_class).getDeclaredFields()) {Class type field.getType();String name field.getName();perstistent false;StringBuffer retval new StringBuffer();retval.append(\t name ( type )\n);Annotation[] annotations field.getDeclaredAnnotations();if (annotations.length ! 0) {for (int j 0; j annotations.length; j) {retval.append(annotations[j].toString() : annotations[j].annotationType() \n);if (annotations[j].toString().startsWith(javax.persistence)) {perstistent true;}}retval.append(\n);}if (perstistent) {retval2.append(retval);}}} catch (ClassNotFoundException e) {System.out.println(e.toString());return retval2.toString();}return retval2.toString();} 这将生成如下内容 models.controlling.Bill
javax.persistence.Table(schema, uniqueConstraints[], catalog, nameproject_bills): interface javax.persistence.Table
javax.persistence.Entity(name): interface javax.persistence.Entityid (class java.lang.Long)
javax.persistence.Id(): interface javax.persistence.Id
javax.persistence.Column(insertabletrue, scale0, uniquefalse, precision0, columnDefinition, namePBI_ID, updatabletrue, length255, nullabletrue, table): interface javax.persistence.ColumnbillAmount (class java.lang.Double)
utils.data.formatters.Formats$DoubleFormat(): interface utils.data.formatters.Formats$DoubleFormat
javax.persistence.Column(insertabletrue, scale0, uniquefalse, precision0, columnDefinition, namePBI_BILL_AMOUNT, updatabletrue, length22, nullabletrue, table): interface javax.persistence.ColumnbillDate (class java.util.Date)
javax.persistence.Column(insertabletrue, scale0, uniquefalse, precision0, columnDefinition, namePBI_BILL_DATE, updatabletrue, length255, nullabletrue, table): interface javax.persistence.Column
play.data.format.Formats$DateTime(patterndd.MM.yyyy): interface play.data.format.Formats$DateTimebillNumber (class java.lang.String)
javax.persistence.Column(insertabletrue, scale0, uniquefalse, precision0, columnDefinition, namePBI_BILL_NUMBER, updatabletrue, length10, nullabletrue, table): interface javax.persistence.Column 当然这只是冰山一角但是您明白了。 参考 如何使用 Poornerd博客上的JCG合作伙伴 Brian Porter的JPA注释 如何使用反射来记录数据模型 。 翻译自: https://www.javacodegeeks.com/2013/07/how-to-use-reflection-to-document-your-data-model-based-on-jpa-annotations.html声明jpa批注处理器