jpress-代码生成器

1.在开发的时候,我们可以在 jpress 项目的 starter 模块下,建立一个新的代码生成器java类,用于对模块的代码生成,也可以参考 starter 模块,自己编写一个属于自己项目的 starter。

2.示例

2.1 现在需要新增一个news新闻模块,可以定位到jpress下的如下图的目录(专门放生成器的目录)中,新增生成器,代码如下

/**
 * Copyright (c) 2016-2020, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jpress.modulegen;

import io.jpress.codegen.ModuleGenerator;

/**
 * @author
 * @version V1.0
 * @Package io.jboot.codegen
 */
public class NewsModuleGenerator {


    private static String dbUrl = "jdbc:mysql://127.0.0.1:3306/hapress";  // 数据库连接信息
    private static String dbUser = "root";
    private static String dbPassword = "";

    private static String moduleName = "news";    // 模块名称
    private static String dbTables = "news,news_category,news_comment";   // 要生成代码的表,多个用逗号分隔
    private static String optionsTables = "";
    private static String sortTables = "news_category";
    private static String sortOptionsTables = "";
    private static String modelPackage = "io.jpress.module.news.model";     // 存放model和basemodel的包
    private static String servicePackage = "io.jpress.module.news.service";   // 存放service的包


    public static void main(String[] args) {

        ModuleGenerator moduleGenerator = new ModuleGenerator(moduleName, dbUrl, dbUser, dbPassword, dbTables, optionsTables, sortTables, sortOptionsTables, modelPackage, servicePackage);
        moduleGenerator.gen();

    }
}

2.2 直接执行上面类中的main方法即完成代码生成。会在项目根目录下生成对应的模块和代码,生成的代码如下:

jpress-代码生成器

 

上一篇:MEGAN4,MEGAN5和MEGAN6的Linux安装和使用


下一篇:Studio one5 和谐版v5.0.1 R2R Win宿主软件