The basic principle of XDoclet is to add specific additional semantics to the Java code, and then analyze the Javadoc Tag in the code through the XDoclet tool, automatically generate configuration files corresponding to the code, in EJB, Hibernate The use of Struts is relatively wide, Ibatis is more grassroots, there is no such cotton jacket, what to do, the New Year, in order to let ibatis have new clothes, I have to get one. If you don't understand XDoclet, I recommend reading this article: http://www-900.ibm.com/developerWorks/cn/java/J-DOCLET/index.shtml?ca=dwcn-newsletter-java My thinking is to ask Simple, I originally wanted to write an XDT template file, customized some tags in Pojo, I steal a Lai, I saw Hibernate's clothes from famous designers, very envious, I came to an imitation version (so-called A goods), borrowed Its label, another important reason is that many IDEs have supported the editing of the Hibernate tag.
I only borrow 4 labels, to make a small amount (later instance description):
1 @ hibernate.class
2 @ hibernate.discriminator
3 @ hibernate.property - Simple properties, corresponding data table field
4 @ hibernate.component - complex attributes, Ibatis corresponds to another SELECT clause
Now please take an example cat beans MM, User.java:
Package Org.chage.pojo;
Import java.util.list;
/ **
* @ hibernate.class table = "d_user"
* @ hibernate.discriminator column = "userid"
Property = "id" type = "long"
* /
PUBLIC CLASS User {
Private long id;
PRIVATE STRING UserName;
PRIVATE LIST ROLES;
/ ***
* @ hibernate.property column = "user_id"
* /
Public long getId () {return id;}
/ ***
* @ hibernate.property column = "user_name"
Update = "true"
* /
Public long getusername () {return username;}
/ ***
* @ hibernate.component
Column = "user_id" select = "SELECTROLES"
* /
Public List Gtroles () {Return Roles;
// The following omitted setter method
......
}
The blue mark is newly added, from the literal mean, you can understand it. The first place is to refer to the attribute corresponding to the primary key field, (God bless, you have nothing to do with the only primary key, this is not luxury) Update = "True" is to indicate the update field to indicate the update, and @ hibernate.component is to implement one-to-one or one-to-many mapping. Below is the relevant part of Build.xml:
Finally, give this XDT template:
XML Version = "1.0" encoding = "UTF-8" Standalone = "no"?>
#, XDtMethod: ifMethodTagValueEquals> XDtMethod: ifHasMethodTag> XDtMethod: ifIsGetter> XDtMethod: forAllClassMethods> where
There is a depressed thing that in the insert and update clause, the list of fields has a comma in the last side, there is time to say, it's almost the New Year, the people are scattered, the team ...