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

JSP
Java 创建cookie和删除cookie
jsp 从web.xml读取连接数据库的参数
jsp 不支持EL表达式,解决办法
jsp 获取客户端的浏览器和操作系统信息
struts2 session 解读
struts2 spring整合fieldError问题
jsp 生成验证码代码
搭建java WEB开发环境和应用
JSP 自定义标签
Java 区分文本中的中英文字符函数
通用JSP页面 jsp入门级文章
jsp struts1 标签实例详解
一个jdbc 测试程序代码
SSH整合中 hibernate托管给Spring得到SessionFactory
jsp SmartUpload 实现上传功能代码
jsp Unsupported encoding: gb2312 错误原因
java Struts2 在拦截器里的跳转问题
jsp 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)
Java 项目生成静态页面的代码
jdk与jre的区别 很形象,很清晰,通俗易懂

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


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