利用MyEclipse的ant插件生成Hibernate的映射文件

先下载:xdoclet-plugins-dist-1.0.4-bin



build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="OA系统构建脚本" default="生成Hibernate配置文件" basedir=".">

    <property name="src.dir" value="${basedir}/src"/>

<!-- 配置路径  指定xdoclet-plugins-dist-1.0.4-bin文件的路径 -->
    <property name="xdoclet.home" value="E:\SoftDownload\xdoclet-plugins-dist-1.0.4-bin\xdoclet-plugins-dist-1.0.4"/>
    
    <!-- build classpath -->
    <path id="xdoclet.task.classpath">
        <fileset dir="${xdoclet.home}/lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    
    <taskdef
        name="xdoclet"
        classname="org.xdoclet.ant.XDocletTask"
        classpathref="xdoclet.task.classpath"
    />
    
    <target name="生成Hibernate配置文件">
        <xdoclet>
            <fileset dir="${src.dir}/com/oa/model">
                <include name="**/*.java"/>
            </fileset>
            <component
                classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
                destdir="${src.dir}"
                version="3.0"
                hbm2ddlauto="update"
                jdbcurl="jdbc:mysql://localhost/oa2"
                jdbcdriver="com.mysql.jdbc.Driver"
                jdbcusername="root"
                jdbcpassword="****"
                dialect="org.hibernate.dialect.MySQLDialect"
                showsql="true"
            />
            
        </xdoclet>
    </target>
    
    <target name="生成hibernate映射文件">
        <xdoclet>
            <fileset dir="${src.dir}/com/oa/model">
                <include name="**/*.java"/>
            </fileset>
            <component
                classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
                version="3.0"
                destdir="${src.dir}"
            />
        </xdoclet>
    </target>   
</project>


java文件

package com.oa.model;
/**
 *
 * @author zudajun225
 * @hibernate.class table="t_person"
 */
public class Person {
    /**
     * @hibernate.id
     *         generator-class="native"
     */
    private int id;
    /**
     * @hibernate.property
     */
    private String name;
    /**
     * @hibernate.property
     */
    private String sex;
    /**
     * @hibernate.property
     */
    private String address;
    /**
     * @hibernate.property
     */
    private String duty;
    /**
     * @hibernate.property
     */
    private String phone;
    /**
     * @hibernate.property
     */
    private String description;
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDuty() {
        return duty;
    }

    public void setDuty(String duty) {
        this.duty = duty;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    
    
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值