在线不卡日本ⅴ一区v二区_精品一区二区中文字幕_天堂v在线视频_亚洲五月天婷婷中文网站

  • <menu id="lky3g"></menu>
  • <style id="lky3g"></style>
    <pre id="lky3g"><tt id="lky3g"></tt></pre>

    搭建低代碼平臺plus代碼生成器的集成

    搭建低代碼平臺plus代碼生成器的集成

    mybatis-plus提供了代碼自動生成器;使用代碼生成器可以根據(jù)數(shù)據(jù)庫表結(jié)構生成我們需要的代碼結(jié)構,節(jié)省了我們建各種類的時間。

    以下是集成mybatis-plus代碼生成器的具體配置:

    pom.xml

    com.baomidou mybatis-plus-generator ${mybatis-plus.version} compile

    代碼生成器工具類

    public class CodeGeneration { public static String scanner (String tip){ Scanner scanner = new Scanner(System.in); StringBuilder help = new StringBuilder(); help.append(“請輸入” + tip + “:”); System.out.println(help.toString()); if (scanner.hasNext()) { String ipt = scanner.next(); /*if (StringUtils.isNotEmpty(ipt)) { return ipt; }*/ if (ipt.length()>0) { return ipt; } } throw new MybatisPlusException(“請輸入正確的” + tip + “!”); } public static void main (String[]args){ // 代碼生成器 AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); String projectPath = “D:/JAVA/crmvideo/src/main/java”; gc.setOutputDir(projectPath); gc.setAuthor(“wlx”); gc.setOpen(false); mpg.setGlobalConfig(gc); // 數(shù)據(jù)源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl(“jdbc:mysql://127.0.0.1:3306/crmvideo?characterEncoding=utf8&serverTimezone=UTC”); dsc.setDriverName(“com.mysql.jdbc.Driver”); dsc.setUsername(“root”); dsc.setPassword(“123456”); mpg.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setModuleName(scanner(“模塊名”)); pc.setParent(“com.wangkai”); pc.setController(“controller”); pc.setService(“service”); pc.setServiceImpl(“serviceImpl”); pc.setMapper(“mapper”); pc.setEntity(“entity”); pc.setXml(“xml”); mpg.setPackageInfo(pc); // 自定義配置 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { // to do nothing } }; // 如果模板引擎是 freemarker String templatePath = “/templates/mapper.xml.ftl”; // 自定義輸出配置 List focList = new ArrayList(); // 自定義配置會被優(yōu)先輸出 focList.add(new FileOutConfig(templatePath) { @Override public String outputFile(TableInfo tableInfo) { return projectPath + “/com/wangkai/” + pc.getModuleName() + “/xml/” +tableInfo.getEntityName() + “Mapper” + StringPool.DOT_XML; } }); cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); // 配置模板 TemplateConfig templateConfig = new TemplateConfig(); // 配置自定義輸出模板 //指定自定義模板路徑,注意不要帶上.ftl/.vm, 會根據(jù)使用的模板引擎自動識別 // templateConfig.setEntity(“templates/entity2.java”); // templateConfig.setService(); // templateConfig.setController(); templateConfig.setXml(null); mpg.setTemplate(templateConfig); // 策略配置 StrategyConfig strategy = new StrategyConfig(); strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setEntityLombokModel(true); strategy.setRestControllerStyle(true); strategy.setSuperEntityColumns(“id”); strategy.setInclude(scanner(“表名,多個英文逗號分割”).split(“,”)); strategy.setControllerMappingHyphenStyle(true); strategy.setTablePrefix(pc.getModuleName() + “_”); mpg.setStrategy(strategy); mpg.setTemplateEngine(new FreemarkerTemplateEngine()); mpg.execute(); }}

    代碼生成器生成的代碼結(jié)構

    代碼生成器生成的代碼結(jié)構

    鄭重聲明:本文內(nèi)容及圖片均整理自互聯(lián)網(wǎng),不代表本站立場,版權歸原作者所有,如有侵權請聯(lián)系管理員(admin#wlmqw.com)刪除。
    上一篇 2022年7月21日 09:45
    下一篇 2022年7月21日 09:45

    相關推薦

    聯(lián)系我們

    聯(lián)系郵箱:admin#wlmqw.com
    工作時間:周一至周五,10:30-18:30,節(jié)假日休息