当前位置: 首页 > 图文教程 > 网络编程 > JSP > 利用Ant和XDoclet自动产生映射文件例子

JSP
GET 方式提交的含有特殊字符的参数
java big5到gb2312的编码转换
java Lucene 中自定义排序的实现
hibernate中的增删改查实现代码
jsp 定制标签(Custom Tag)
jsp基础速成精华讲解
IE cache缓存 所带来的问题收藏
关于JSP的一点疑问小结
JSP 多条SQL语句同时执行的方法
jsp include文件时的一个乱码解决方法
在JSTL EL中处理java.util.Map,及嵌套List的情况
jsp 页面显示的一些用法
根据Hibernte的cfg文件生成sql文件
五种 JSP页面跳转方法详解
JSP 防范SQL注入攻击分析
JSP 连接MySQL配置与使用
java eclipse 启动参数
jsp 页面上图片分行输出小技巧
解决jsp开发中不支持EL问题
JSP 页面中使用FCKeditor控件(js用法)

JSP 中的 利用Ant和XDoclet自动产生映射文件例子


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-03   浏览: 98 ::
收藏到网摘: n/a

//User.java
  1. package dbdemo;
  2. import java.util.Date;
  3. import java.util.Set;
  4. /**
  5.  * @hibernate.class table="Users"
  6.  *
  7.  * @author MEagle
  8.  *
  9.  * Represents a User
  10.  */
  11. public class User {
  12.     private String userID;
  13.     private String userName;
  14.     private String password;
  15.     private String emailAddress;
  16.     private Date lastLogon;
  17.     private Set contacts;
  18.     private Set books;
  19.     private Address address;
  20.     /**
  21.      * @hibernate.property column="EmailAddress" type="string"
  22.      * @return String
  23.      */
  24.     public String getEmailAddress() {
  25.         return emailAddress;
  26.     }
  27.     /**
  28.      * @hibernate.property column="LastLogon" type="date"
  29.      * @return Date
  30.      */
  31.     public Date getLastLogon() {
  32.         return lastLogon;
  33.     }
  34.     /**
  35.      * @hibernate.property column="Password" type="string"
  36.      * @return String
  37.      */
  38.     public String getPassword() {
  39.         return password;
  40.     }
  41.     /**
  42.      * @hibernate.id generator-class="assigned" type="string"
  43.      *                      column="LogonID"
  44.      * @return String
  45.      */
  46.     public String getUserID() {
  47.         return userID;
  48.     }
  49.     /**
  50.      * @hibernate.property column="Name" type="string"
  51.      * @return String
  52.      */
  53.     public String getUserName() {
  54.         return userName;
  55.     }
  56.     /**
  57.      * @param string
  58.      */
  59.     public void setEmailAddress(String string) {
  60.         emailAddress = string;
  61.     }
  62.     /**
  63.      * @param string
  64.      */
  65.     public void setLastLogon(Date date) {
  66.         lastLogon = date;
  67.     }
  68.     /**
  69.      * @param string
  70.      */
  71.     public void setPassword(String string) {
  72.         password = string;
  73.     }
  74.     /**
  75.      * @param string
  76.      */
  77.     public void setUserID(String string) {
  78.         userID = string;
  79.     }
  80.     /**
  81.      * @param string
  82.      */
  83.     public void setUserName(String string) {
  84.         userName = string;
  85.     }
  86.     /**
  87.      * @hibernate.set role="contacts" table="Contacts"
  88.      *                        cascade="all" readonly="true"
  89.      * @hibernate.collection-key column="User_ID"
  90.      * @hibernate.collection-one-to-many class="dbdemo.Contact"
  91.      * @return java.util.Set
  92.      */
  93.     public Set getContacts() {
  94.         return contacts;
  95.     }
  96.     /**
  97.      * @param set
  98.      */
  99.     public void setContacts(Set set) {
  100.         contacts = set;
  101.     }
  102.     /**
  103.      * @hibernate.set role="books" table="Book_User_Link"
  104.      *                            cascade="all" eadonly="true"
  105.      * @hibernate.collection-key column="UserID"
  106.      * @hibernate.collection-many-to-many
  107.      *                            class="dbdemo.Book" column="BookID"
  108.      * @return java.util.Set
  109.      */
  110.     public Set getBooks() {
  111.         return books;
  112.     }
  113.     /**
  114.      * @param set
  115.      */
  116.     public void setBooks(Set set) {
  117.         books = set;
  118.     }
  119.     /**
  120.      * @hibernate.one-to-one class="dbdemo.Address"
  121.      * @return dbdemo.Address
  122.      */
  123.     public Address getAddress() {
  124.         return address;
  125.     }
  126.     /**
  127.      * @param address
  128.      */
  129.     public void setAddress(Address address) {
  130.         this.address = address;
  131.     }
  132. }

//Ant build File build.xml
  1.  <project name="Hibernate Example" default="about" basedir=".">
  2.  
  3.        <!-- The location where your xdoclet jar files reside -->
  4.  
  5.        <property name="xdoclet.lib.home" value="c:/java_api/xdoclet-1.2b3/lib"/>
  6.  
  7.  
  8.  
  9.        <target name="clean" depends="init" description="removes all directories
  10. related to this build">
  11.  
  12.              <delete dir="${dist}"/>
  13.  
  14.        </target>
  15.  
  16.  
  17.        <target name="init" description="Initializes properties that are used by
  18. other targets.">
  19.              <property name="dist" value="dist"/>
  20.        </target>
  21.  
  22.        <target name="prepare" depends="init,clean" description="creates dist dir
  23. ectory">
  24.              <echo message="Creating required directories..."/>
  25.              <mkdir dir="${dist}"/>
  26.        </target>
  27.  
  28.        <target name="hibernate" depends="prepare"
  29.          description="Generates Hibernate class descriptor files.">
  30.              <taskdef name="hibernatedoclet"                 classname="xdoclet.
  31. modules.hibernate.HibernateDocletTask">                  <classpath>
  32.                    <fileset dir="${xdoclet.lib.home}">
  33.                        <include name="*.jar"/>
  34.                    </fileset>
  35.                  </classpath>
  36.              </taskdef>
  37.  
  38.              <!-- Execute the hibernatedoclet task -->
  39.  
  40.              <hibernatedoclet
  41.                    destdir="."
  42.                    excludedtags="@version,@author,@todo"
  43.                    force="true"
  44.                    verbose="true"
  45.                    mergedir="${dist}">
  46.  
  47.                    <fileset dir=".">
  48.                        <include name="**/dbdemo/*.java"/>
  49.                    </fileset>
  50.  
  51.                    <hibernate version="2.0"/>
  52.  
  53.              </hibernatedoclet>
  54.        </target>
  55.  
  56.        <target name="about" description="about this build file" depends="init">
  57.              <echo message="  Use this format for the arguments:"/>
  58.              <echo message="      ant hibernate"/>
  59.              <echo message=""/>
  60.        </target>
  61.  
  62.  </project>


ant hibernate
映射文件.hbm.xml 自动生成了.
http://voxel.dl.sourceforge.net/sourceforge/xdoclet/xdoclet-bin-1.2.2.zip