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

JSP
我认为JSP有问题(上)
我认为JSP有问题(下)
jsp“抓”网页代码的程序
关于在bean里面打印html的利弊看法
bean里面如何打印到html页面
jdbc3中的RowSet 接口规范
Apusic Application Server1.0中jsp源代码泄漏漏洞
Unify的eWave ServletExec拒绝服务漏洞
通过提交超长的GET请求导致IBM HTTP Server远程溢出
在HTTP请求中添加特殊字符导致暴露JSP源代码文件
Resin 1.2 重要源代码暴露漏洞
多中WEB服务器的通用JSp源代码暴露漏洞
Tomcat 暴露JSP文件内容
IBM WebSphere Application Server 暴露JSP文件内容
JRun 2.3.x 范例文件暴露站点安全信息
BEA WebLogic 暴露源代码漏洞
IBM WebSphere Application Server 3.0.2 存在暴露源代码漏洞
Tomcat 3.1 存在暴露网站路径问题
Sun Java Web Server 能让攻击者远程执行任意命令
Netscape 修复 JAVA 安全漏洞

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


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