AppFuse代碼產生器(AMP)

來源:互聯網
上載者:User

AMP(appfuse maven plugin)

建立一個javaBean

package org.appfuse.model;import javax.persistence.Entity;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.GeneratedValue;import javax.persistence.Column;import org.apache.commons.lang.builder.EqualsBuilder;import org.apache.commons.lang.builder.HashCodeBuilder;import org.apache.commons.lang.builder.ToStringBuilder;@Entitypublic class Persion extends BaseObject {       private Long id ;       private String firstName ;       private String lastName ;       @Id       @GeneratedValue(strategy = GenerationType.AUTO)       public Long getId() {             return id ;      }       public void setId(Long id) {             this.id = id;      }       @Column(name = "first_name" , length = 50)       public String getFirstName() {             return firstName ;      }       public void setFirstName(String firstName) {             this.firstName = firstName;      }       @Column(name = "last_name" , length = 50)       public String getLastName() {             return lastName ;      }       public void setLastName(String lastName) {             this.lastName = lastName;      }       /**       * @see java.lang.Object#equals(Object)       */       public boolean equals(Object object) {             if (!(object instanceof Persion)) {                   return false ;            }            Persion rhs = (Persion) object;             return new EqualsBuilder().append(this. firstName, rhs.firstName)                        .append( this.id , rhs.id).append( this.lastName , rhs.lastName)                        .isEquals();      }       /**       * @see java.lang.Object#hashCode()       */       public int hashCode() {             return new HashCodeBuilder(248915313, 1539783955)                        .append( this.firstName ).append(this. id).append( this.lastName )                        .toHashCode();      }       /**       * @see java.lang.Object#toString()       */       public String toString() {             return new ToStringBuilder(this).append( "lastName", this.lastName )                        .append( "id", this .id ).append("firstName", this.firstName )                        .toString();      }}

在命令列下運行mvn appfuse:gen -Dentity=Persion,這個POJO的CRUD代碼即被產生,並自動添加到項目中。注意:預設的類名是在 ${groupId}.model.Persion下面,如果想指定一個子包名,需要指定全部路徑,不如產生${groupId}.subPackage.model.Persion.   mvn appfuse:gen -Dentity={groupId}.subPackage.model.Persion

hibernate.cfg.xml 添加了Persion 對應的mapping<hibernate-configuration>    <session-factory >        <mapping class ="org.appfuse.model.User" />        <mapping class ="org.appfuse.model.Role" />        <mapping class ="com.mapbar.model.Persion" />    </session-factory ></hibernate-configuration>
接下來根據這個POJO產生資料表。
在命令列下運行mvn compile hibernate3:hbm2ddl。 此時資料庫中添加了此POJO對應的表。mvn appfuse:gen-model是appfuse maven plugin(簡稱AMP)中的一個命令,用以從資料庫反向工程產生pojo。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.