发帖  主题  评论  推荐  标签 用户 查搜   用户 密码 自动 注册  
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 CQRS 扩展性 并发编程 事件溯源 分布式 SOA

MinuteProject快速生成源码

  MinuteProject是一个能够一次性生成源码的反转工程(reverse-engineering) 工具,也就是代码生成器,它能够产生各种开源堆栈的应用代码,后端根据已经存在数据表产生的代码包括: Hibernate, JPA, JPA2, springframework. REST: JEE-jersey, CXF, springMVC.等等;前端代码包括Openxava, Grails, Play. Methodology: FitNesse.还有: vaadin, jsf-primefaces, jooq, rails等

首先,下载MinuteProject,有命令和GUI两种方式启动:

1. 在解压后的项目/bin/start-console.cmd 或start-console.sh 启动GUI,如下图:

你可以选择你使用的数据库,目前支持下面几种:Oracle; DB2; Mysql; hsqldb; derby。

填写好数据库连接,比如mysql是:jdbc:mysql://127.0.0.1:3306/test,其中 test是你建立的数据库名称,输入用户名和密码,schema是已经存在的一个数据表,MinuteProject将根据这个表结构产生相应的模型和DAO代码。

roo package是指你的代码的包名,比如com.jdon,模型名称是你的业务模型名称,比如Order或Product等等。

下面可以选择target类型,也就是你需要生成代码的类型,有如下:

  • Maven Spring Hibernate (advanced DAO)
  • Maven Spring JPA/Hibernate (advanced DAO)
  • FitNesse
  • Spring/Hibernate (standard)
  • Spring/JPA/Hibernate (standard)
  • Spring/iBatis (standard)
  • OpenXava
  • Grails
  • Play
  • JPA2
  • JSF-primefaces
  • REST-JEE
  • WS-JEE

选择产生的代码类型后,点按generate,在项目目录output下生成了代码,如果你没有发现这个目录,主要可能是你的数据库参数没有配置正确。

 

2.命令行生成代码方式

在项目的/mywork/config目录下有一个样本配置文件:mp-config-sample.xml,根据你安装的数据库配置这个配置文件,存成另外一个文件如Hello.xml,里面的mysql配置如下:

<!DOCTYPE root>

<generator-config xmlns="http://minuteproject.sf.net/xsd/mp-config"

xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"

xs:noNamespaceSchemaLocation="mp-config.xsd">

       <configuration>

              <model name="Hello" version="1.0" package-root="com.jdon.demo">

                     <data-model>

                        

                <driver name="mysql" version="5.0.5" groupId="mysql" artifactId="mysql-connector-java"></driver>                                               

                <dataSource>

                       <driverClassName>org.gjt.mm.mysql.Driver</driverClassName>

                       <url>jdbc:mysql://localhost:3306/test</url>

                       <username>banq</username>

                       <password>xxxx</password>

                </dataSource>              

                              <!-- autoincrement primary key                         -->

                            <primaryKeyPolicy>

                                   <primaryKeyPolicyPattern name="autoincrementPattern" ></primaryKeyPolicyPattern>

                            </primaryKeyPolicy>

 

                     </data-model>

                     <business-model>

                            <generation-condition>

                                   <condition type="exclude" startsWith="SYS_ADMIN"></condition>

                            </generation-condition>

                           

                            <business-package default="model">

                                   <condition type="package" startsWith="TB_" result="other"></condition>

                            </business-package>            

                           

                            <!-- Enrichment gives extra information that can be used by the template

                                    Ex: one concept such as indicating that an entity contains master data can trigger specific artifact generation on multiple level:

                                        - specific DAO,

                                        - cache configuration,

                                        - presentation navigation behaviour (access to the entity via drop down list and not classical affection Sub Use Case)

                                        - enumeration (strong typing) in some cases

                                        - sql constraint statement in some cases     

                                    Enrichment   can target entities, fields, business package

                            -->

                            <enrichment>

                                <!-- content-type enrichment -->

                                   <entity name="CATEGORY" content-type="reference-data" >

                                      <!-- TODO semantic reference -->

                                   </entity>

                                  

                                  

                                  

                                   <!-- constraining a field -->

                            </enrichment>                                  

                     </business-model>

              </model>

              <!-- change your catalog entry with one of the track -->

              <targets catalog-entry="JOOQ"/>

 

 

       </configuration>

</generator-config>

其中targets catalog-entry="JOOQ"是选择你生成代码的架构类型,这里是JOOQ。

在此目录下运行:

model-generation.cmd Hello.xml

那么在与当前config平行的目录/mywork/output下产生了代码。

例如testuser表产生的DAO接口TestuserDao代码如下:

public interface TestuserDao {

    /**

     * Inserts a Testuser entity

     * @param Testuser testuser

     */

    public void insertTestuser(Testuser testuser) ;

 

    /**

     * Inserts a list of Testuser entity

     * @param List<Testuser> testusers

     */

    public void insertTestusers(List<Testuser> testusers) ;

       

    /**

     * Updates a Testuser entity

     * @param Testuser testuser

     */

    public Testuser updateTestuser(Testuser testuser) ;

 

        /**

     * Updates a Testuser entity with only the attributes set into Testuser.

        * The primary keys are to be set for this method to operate.

        * This is a performance friendly feature, which remove the udibiquous full load and full update when an

        * update is to be done

   * Remark: The primary keys cannot be update by this methods, nor are the attributes that must be set to null.

   * @param Testuser testuser

   */

    public int updateNotNullOnlyTestuser(Testuser testuser) ;

        

       public int updateNotNullOnlyPrototypeTestuser(Testuser testuser, Testuser prototypeCriteria);

      

     /**

     * Saves a Testuser entity

     * @param Testuser testuser

     */

    public void saveTestuser(Testuser testuser);

   

    /**

     * Deletes a Testuser entity

     * @param Testuser testuser

     */

    public void deleteTestuser(Testuser testuser) ;

 

    /**

     * Loads the Testuser entity which is related to an instance of

     * Testuser

     * @param Long id

     * @return Testuser The Testuser entity

    

    public Testuser loadTestuser(Long id);

*/

    /**

     * Loads the Testuser entity which is related to an instance of

     * Testuser

     * @param java.lang.String Userid

     * @return Testuser The Testuser entity

     */

    public Testuser loadTestuser(java.lang.String userid);   

 

    /**

     * Loads a list of Testuser entity

     * @param List<java.lang.String> userids

     * @return List<Testuser> The Testuser entity

     */

    public List<Testuser> loadTestuserListByTestuser (List<Testuser> testusers);

   

    /**

     * Loads a list of Testuser entity

     * @param List<java.lang.String> userids

     * @return List<Testuser> The Testuser entity

     */

    public List<Testuser> loadTestuserListByUserid(List<java.lang.String> userids);

   

    /**

     * Loads the Testuser entity which is related to an instance of

     * Testuser and its dependent one to many objects

     * @param Long id

     * @return Testuser The Testuser entity

     */

    public Testuser loadFullFirstLevelTestuser(java.lang.String userid);

   

    /**

     * Loads the Testuser entity which is related to an instance of

     * Testuser

     * @param Testuser testuser

     * @return Testuser The Testuser entity

     */

    public Testuser loadFullFirstLevelTestuser(Testuser testuser);   

   

   

    /**

     * Loads the Testuser entity which is related to an instance of

     * Testuser and its dependent objects one to many

     * @param Long id

     * @return Testuser The Testuser entity

     */

    public Testuser loadFullTestuser(Long id) ;

 

    /**

     * Searches a list of Testuser entity based on a Testuser containing Testuser matching criteria on the positive mask

     * @param Testuser testuser

     * @return List<Testuser>

     */

    public List<Testuser> searchPrototypeTestuser(Testuser testuser) ;

   

 

    /**

     * Searches a list of Testuser entity based on a Testuser containing Testuser matching criteria on any field

     * @param Testuser testuser

     * @return List<Testuser>

     */

    public List<Testuser> searchPrototypeAnyTestuser(Testuser testuser) ;

 

    public List<Testuser> find (Testuser testuser, EntityMatchType matchType, OperandType operandType, Boolean caseSensitivenessType) ;

 

    /**

     * Searches a list of Testuser entity based on a list of Testuser containing Testuser matching criteria

     * @param List<Testuser> testusers

     * @return List<Testuser>

     */

    public List<Testuser> searchPrototypeTestuser(List<Testuser> testusers) ;   

          

       /**

     * Searches a list of Testuser entity

     * @param Testuser testuser

     * @return List

     */

    public List<Testuser> searchPrototypeTestuser(Testuser testuserPositive, Testuser testuserNegative) ;

 

}

 

 

解道移动版 | 关注解道 | 联系解道 | 关于解道 | 广告联系 | 网站地图 | 设为首页

沪ICP证12033263 如有意见请与我们联系 Powered by JdonFramework
返回顶部