简单OA项目笔记(6):Ant+XDoclet


ant类似makefile
XDoclet是根据注释生成struts的struts-config.xml配置文件、javascript校验等。


初步感觉这两个结合只要是为了自动生成hibernate.cfg.xml,现在我爱用Annotation,这个用处不大。仅记录一下 以后好查找


build.xml

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

	<property name="src.dir" value="${basedir}/src"/><!-- 源代码目录 -->
	<property name="xdoclet.home" value="D:/xdoclet-plugins-dist-1.0.4"/><!-- XDoclet目录 -->
	
	<!-- build classpath -->
	<path id="xdoclet.task.classpath">
		<fileset dir="${xdoclet.home}/lib">
			<include name="**/*.jar"/><!-- 上述目录下以及子目录下的,所有jar文件 -->
		</fileset>
	</path>
	
	<!-- 自定义ant任务 -->
	<taskdef 
		name="xdoclet"
		classname="org.xdoclet.ant.XDocletTask"
		classpathref="xdoclet.task.classpath"
	/>
	
	<target name="生成Hibernate配置文件(hibernate.cfg.xml)">
		<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/oa"
				jdbcdriver="com.mysql.jdbc.Driver"
				jdbcusername="root"
				jdbcpassword="123"
				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>



model中写一个XDoclet能是别的注释,表名是t_user

/**
 * 
 * @author zudajun225
 * @hibernate.class table="t_user"
 */
public class User {
	/**
	 * @hibernate.id
	 * 		generator-class="native"
	 */
	private int id;
	/**
	 * 登陆账号
	 * @hibernate.property
	 * 			not-null="true"
	 * 			unique="true"
	 */
	private String username;
	/**
	 * 登陆密码
	 * @hibernate.property
	 * 			not-null="true"
	 */
	private String  password;
	/**
	 * 创建时间
	 * @hibernate.property update="false"
	 */
	private Date createTime;
	/**
	 * 失效时间
	 * @hibernate.property
	 */
	private Date expireTime;
	/**
	 * 人员信息
	 * @hibernate.many-to-one
	 * 			unique="true"
	 */
	private Person person;









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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值