1. 建立表userinfo
列名 | 描述 |
UserID | 主鍵、自增 |
UserName | 使用者名稱 |
Pwd | 密碼 |
CreateDate | 建立日期 |
2. 在src/main/resources目錄下增加檔案hibernate.reveng.xml,並在pom.xml中配置build子標籤
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> <type-mapping> <!-- jdbc-type is name fom java.sql.Types --> <sql-type jdbc-type="VARCHAR" length='1' hibernate-type="yes_no"/> <!-- length, scale and precision can be used to specify the mapping precisly --> <sql-type jdbc-type="NUMERIC" precision='1' hibernate-type="boolean"/> <!-- the type-mappings are ordered. This mapping will be consulted last, thus overriden by the previous one if precision=1 for the column --> <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long"/> <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Long"/> <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long"/> </type-mapping> <table-filter match-name="*" exclude="true"/> <table-filter match-name="userinfo" exclude="false"/> </hibernate-reverse-engineering>
1 <plugin> 2 <groupId>org.appfuse.plugins</groupId> 3 <artifactId>appfuse-maven-plugin</artifactId> 4 <version>${project.parent.version}</version> 5 <configuration> 6 <componentProperties> 7 <revengfile>src/main/resources/hibernate.reveng.xml</revengfile> 8 </componentProperties> 9 <genericCore>${amp.genericCore}</genericCore> 10 <fullSource>${amp.fullSource}</fullSource> 11 </configuration> 12 <dependencies> 13 <dependency> 14 <groupId>${jdbc.groupId}</groupId> 15 <artifactId>${jdbc.artifactId}</artifactId> 16 <version>${jdbc.version}</version> 17 </dependency> 18 </dependencies> 19 </plugin>
3. 開啟命令列,輸入mvn appfuse:gen-model 生成實體類userinfo.java
package com.zcmp.disappearwind.model; import com.zcmp.disappearwind.model.BaseObject; import org.hibernate.search.annotations.DocumentId; import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; @Entity @Table(name="userinfot",catalog="disappearwind") @Indexed @XmlRootElement public class Userinfo extends BaseObject implements Serializable { private Long userId; private Date createDate; private String pwd; private String userName; @Id @GeneratedValue(strategy=IDENTITY) @DocumentId public Long getUserId() { return this.userId; } public void setUserId(Long userId) { this.userId = userId; } @Temporal(TemporalType.TIMESTAMP) @Column(name="CreateDate", length=19) @Field public Date getCreateDate() { return this.createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } @Column(name="Pwd", length=128) @Field public String getPwd() { return this.pwd; } public void setPwd(String pwd) { this.pwd = pwd; } @Column(name="UserName", length=128) @Field public String getUserName() { return this.userName; } public void setUserName(String userName) { this.userName = userName; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Userinfo pojo = (Userinfo) o; if (createDate != null ? !createDate.equals(pojo.createDate) : pojo.createDate != null) return false; if (pwd != null ? !pwd.equals(pojo.pwd) : pojo.pwd != null) return false; if (userName != null ? !userName.equals(pojo.userName) : pojo.userName != null) return false; return true; } public int hashCode() { int result = 0; result = (createDate != null ? createDate.hashCode() : 0); result = 31 * result + (pwd != null ? pwd.hashCode() : 0); result = 31 * result + (userName != null ? userName.hashCode() : 0); return result; } public String toString() { StringBuffer sb = new StringBuffer(getClass().getSimpleName()); sb.append(" ["); sb.append("userId").append("='").append(getUserId()).append("', "); sb.append("createDate").append("='").append(getCreateDate()).append("', "); sb.append("pwd").append("='").append(getPwd()).append("', "); sb.append("userName").append("='").append(getUserName()).append("'"); sb.append("]"); return sb.toString(); } }
4. 在命令號執行mvn appfuse:gen生成頁面、Controller、menu配置等檔案,注意提示輸入實體名的時候大小寫一定要和第三步生成的類名保持一致
5. 開啟ApplicationResources_zh.properties檔案,漢化各欄位的名稱以及各種標題和提示資訊
6. 重新部署即可