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

JSP
Servlet及JSP中的多线程同步问题
使用Ant和Tomcat创建Web应用
如何直接在浏览器内运行SQL命令
Servlet、Jsp中的多国语言显示
html与jsp开发分离技术
通过Jsp发送动态图像
Servlets和JSP Pages最佳实践
学习在JSP中使用JavaBeans
JSP显示内容缓存技巧
应用JDOM处理数据库到XML转换的JSP实现
JSP中tomcat的SQL Server2000数据库连接池的配置
用JSTL实现JSP应用程序快速开发
浅谈4种类型的JDBC驱动程序
怎样设置 JSP 的虚拟目录
Java 中对文件的读写操作之比较
javamail在jsp中调用
jsp中任意文字转Unicode的通用模块
JSP与SQL SERVER的留言本
jspSmartUpload上传下载全攻略
Tomcat5.x中的虚拟主机配置方法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-03   浏览: 68 ::
收藏到网摘: 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