XDoclet使用:
下载http://xdoclet.codehaus.org/
Ant+XDoclet:
在工程里创建一个需要映射的对象
下载http://xdoclet.codehaus.org/
Ant+XDoclet:
在工程里创建一个需要映射的对象
/**
* @author kristain
* @hibernate.class table="t_user"
*/
public class User {
/**
* @hibernate.id
* generator-class="native"
*/
private int id;
/**
* @hibernate.property
*/
private String username;
/**
* @hibernate.property
*/
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
建立build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="构建脚本" default="生成Hibernate配置脚本" basedir=".">
<property name="src.dir" value="${basedir}/src"/>
<property name="xdoclet.home" value="D:/commons/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/model">
<include name="**/*.java"/>
</fileset>
</xdoclet>
<component
classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
destdir="${src.dir}"
version="3.0"
jdbcurl="jdbc:mysql://localhost/oa"
jdbcdriver="com.mysql.jdbc.Driver"
jdbcusername="root"
jdbcpassword="root"
dialect="org.hibernate.dialect.MySQLDialect"
showsql="true"
/>
</target>
<target name="生成hibernate映射文件">
<xdoclet>
<fileset dir="${src.dir}/com/model">
<include name="**/*.java"/>
</fileset>
<component
classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
version="3.0"
destdir="${src.dir}"
/>
</xdoclet>
</target>
</project>
在myeclipse中使用ant控制台,添加build.xml,运行生成hibernate配置文件
当一个人找不到出路的时候,最好的办法就是将当前能做好的事情做到极致,做到无人能及。
浙公网安备 33010602011771号