From ef5dda6db97f89c09a714b9304f302c00ee4ac6c Mon Sep 17 00:00:00 2001 From: wuyouming666 <2265557248@qq.com> Date: 星期二, 16 一月 2024 13:53:07 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes --- springboot-vue3/src/main/java/MyGenerator.java | 352 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 176 insertions(+), 176 deletions(-) diff --git a/springboot-vue3/src/main/java/MyGenerator.java b/springboot-vue3/src/main/java/MyGenerator.java index 0be7461..46475de 100644 --- a/springboot-vue3/src/main/java/MyGenerator.java +++ b/springboot-vue3/src/main/java/MyGenerator.java @@ -1,176 +1,176 @@ - - -import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.generator.AutoGenerator; -import com.baomidou.mybatisplus.generator.InjectionConfig; -import com.baomidou.mybatisplus.generator.config.*; -import com.baomidou.mybatisplus.generator.config.po.TableInfo; -import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; -import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; - -import java.util.ArrayList; -import java.util.List; - -/** - * mybatis-plus-generator浠g爜鐢熸垚鍣� - * 淇敼閰嶇疆鍚庣洿鎺ヨ繍琛宮ain鏂规硶鍗冲彲 - */ -public class MyGenerator { - - /** 鏁版嵁婧愰厤缃�*/ - private static final String jdbc = "jdbc:mysql://localhost:3306/canadames?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai"; - private static final String driverName = "com.mysql.cj.jdbc.Driver"; - - private static final String username = "root"; - private static final String password = "beibo.123/"; - /** 鍖呭悕*/ - private static final String moduleName = "device"; - /** 琛ㄥ悕鍓嶇紑*/ - private static final String beginName = "device"; - /** 闇�瑕佺敓鎴愪唬鐮佺殑琛�*/ - private static final String [] tables = new String[]{"device"}; - - - - - public static void main(String[] args) { - - // 瀹樻柟缃戠珯锛歨ttps://baomidou.com/pages/d357af/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7%E6%B3%A8%E5%85%A5 - - // 鍙傝�冪綉绔欙細https://blog.csdn.net/kinghmj01/article/details/97748509 - - // 浠g爜鐢熸垚鍣� - AutoGenerator mpg = new AutoGenerator(); - - // 鍏ㄥ眬閰嶇疆 - GlobalConfig gc = new GlobalConfig(); - // 褰撳墠椤圭洰璺緞 - String projectPath = System.getProperty("user.dir"); - // 褰撳墠椤圭洰鐨勪笅鐨勮矾寰� - gc.setOutputDir(projectPath + "/src/main/java"); - // 浣滆�� - gc.setAuthor("yyq"); - // 鏄惁鎵撳紑杈撳嚭鐩綍 榛樿涓簍rue - gc.setOpen(false); - // 瀹炰綋灞炴�� Swagger2 娉ㄨВ - gc.setSwagger2(true); - - // 鑷畾涔夋枃浠跺懡鍚嶏紝娉ㄦ剰 %s 浼氳嚜鍔ㄥ~鍏呰〃瀹炰綋灞炴�э紒 - gc.setControllerName("%sController"); - gc.setServiceName("%sService"); - gc.setServiceImplName("%sServiceImpl"); - gc.setMapperName("%sDao"); - gc.setEntityName("%sEntity"); - mpg.setGlobalConfig(gc); - - // 鏁版嵁婧愰厤缃� - DataSourceConfig dsc = new DataSourceConfig(); - // dsc.setSchemaName("public"); - dsc.setUrl(jdbc); - dsc.setDriverName(driverName); - dsc.setUsername(username); - dsc.setPassword(password); - mpg.setDataSource(dsc); - - // 璁剧疆鍖呭悕 - PackageConfig pc = new PackageConfig(); - // 鐢ㄤ簬鍖呭悕銆佽〃鍚嶅墠缂� - //pc.setModuleName(moduleName); - // 鐢熸垚鍒伴偅浜涘寘涓� 濡� com.modules涓诲寘涓嬬殑 controller.sys.TestController - pc.setParent("com.canadames"); - pc.setController("controller."+moduleName); - pc.setService("service."+moduleName); - pc.setServiceImpl("service."+moduleName+".impl"); - pc.setMapper("mapper."+moduleName); - pc.setEntity("entity."+moduleName); - mpg.setPackageInfo(pc); - - // 鑷畾涔夐厤缃� - InjectionConfig cfg = new InjectionConfig() { - @Override - public void initMap() { - // to do nothing - } - }; - - // 濡傛灉妯℃澘寮曟搸鏄� freemarker - String templatePath = "/templates/mapper.xml.ftl"; - // 濡傛灉妯℃澘寮曟搸鏄� velocity - // String templatePath = "/templates/mapper.xml.vm"; - - // 鑷畾涔夎緭鍑洪厤缃� - List<FileOutConfig> focList = new ArrayList<>(); - // 鑷畾涔夐厤缃細琚紭鍏堣緭鍑� - focList.add(new FileOutConfig(templatePath) { - @Override - public String outputFile(TableInfo tableInfo) { - // 鑷畾涔夎緭鍑烘枃浠跺悕 锛� 濡傛灉浣� Entity 璁剧疆浜嗗墠鍚庣紑銆佹澶勬敞鎰� xml 鐨勫悕绉颁細璺熺潃鍙戠敓鍙樺寲锛侊紒 - return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; - } - }); - /* - cfg.setFileCreate(new IFileCreate() { - @Override - public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) { - // 鍒ゆ柇鑷畾涔夋枃浠跺す鏄惁闇�瑕佸垱寤� - checkDir("璋冪敤榛樿鏂规硶鍒涘缓鐨勭洰褰曪紝鑷畾涔夌洰褰曠敤"); - if (fileType == FileType.MAPPER) { - // 宸茬粡鐢熸垚 mapper 鏂囦欢鍒ゆ柇瀛樺湪锛屼笉鎯抽噸鏂扮敓鎴愯繑鍥� false - return !new File(filePath).exists(); - } - // 鍏佽鐢熸垚妯℃澘鏂囦欢 - return true; - } - }); - */ - cfg.setFileOutConfigList(focList); - mpg.setCfg(cfg); - - // 閰嶇疆妯℃澘 - TemplateConfig templateConfig = new TemplateConfig(); - - // 閰嶇疆鑷畾涔夎緭鍑烘ā鏉� - //鎸囧畾鑷畾涔夋ā鏉胯矾寰勶紝娉ㄦ剰涓嶈甯︿笂.ftl/.vm, 浼氭牴鎹娇鐢ㄧ殑妯℃澘寮曟搸鑷姩璇嗗埆 - // templateConfig.setEntity("templates/entity2.java"); - // templateConfig.setService(); - // templateConfig.setController(); - - templateConfig.setXml(null); - mpg.setTemplate(templateConfig); - - // 绛栫暐閰嶇疆 - StrategyConfig strategy = new StrategyConfig(); - - //闇�瑕佺敓鎴愮殑琛� - strategy.setInclude(tables); - strategy.setControllerMappingHyphenStyle(true); - //绫诲悕鐢熸垚绛栫暐锛氶┘宄板懡鍚� - strategy.setNaming(NamingStrategy.underline_to_camel); - //瀛楁鍚嶇敓鎴愭柟寮忥細椹煎嘲鍛藉悕 - strategy.setColumnNaming(NamingStrategy.underline_to_camel); - // 琛ㄥ墠缂� - strategy.setTablePrefix(beginName+"_"); - - // 鍐欎簬鐖剁被涓殑鍏叡瀛楁锛堝湪鐖剁被涓凡缁忔湁鐨勪笉闇�瑕佺敓鎴愮殑瀛楁锛� - strategy.setSuperEntityColumns("id", "updateTime", "createTime"); - // 姣忓眰鐨勭户鎵匡紙涓嶉渶瑕佸彲涓嶈缃級 -// strategy.setSuperControllerClass("com.common.controller.MyController"); - strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService"); - strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl"); - strategy.setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper"); - //缁ф壙鐨勫睘鎬х埗绫� -// strategy.setSuperEntityClass("com.common.entity.MyEntity"); - strategy.setEntityLombokModel(true); - strategy.setRestControllerStyle(true); - - mpg.setStrategy(strategy); - - mpg.setTemplateEngine(new FreemarkerTemplateEngine()); - - mpg.execute(); - } - - - -} - + + +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; + +import java.util.ArrayList; +import java.util.List; + +/** + * mybatis-plus-generator浠g爜鐢熸垚鍣� + * 淇敼閰嶇疆鍚庣洿鎺ヨ繍琛宮ain鏂规硶鍗冲彲 + */ +public class MyGenerator { + + /** 鏁版嵁婧愰厤缃�*/ + private static final String jdbc = "jdbc:mysql://localhost:3306/canadames?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai"; + private static final String driverName = "com.mysql.cj.jdbc.Driver"; + + private static final String username = "root"; + private static final String password = "beibo.123/"; + /** 鍖呭悕*/ + private static final String moduleName = "device"; + /** 琛ㄥ悕鍓嶇紑*/ + private static final String beginName = "device"; + /** 闇�瑕佺敓鎴愪唬鐮佺殑琛�*/ + private static final String [] tables = new String[]{"device"}; + + + + + public static void main(String[] args) { + + // 瀹樻柟缃戠珯锛歨ttps://baomidou.com/pages/d357af/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7%E6%B3%A8%E5%85%A5 + + // 鍙傝�冪綉绔欙細https://blog.csdn.net/kinghmj01/article/details/97748509 + + // 浠g爜鐢熸垚鍣� + AutoGenerator mpg = new AutoGenerator(); + + // 鍏ㄥ眬閰嶇疆 + GlobalConfig gc = new GlobalConfig(); + // 褰撳墠椤圭洰璺緞 + String projectPath = System.getProperty("user.dir"); + // 褰撳墠椤圭洰鐨勪笅鐨勮矾寰� + gc.setOutputDir(projectPath + "/src/main/java"); + // 浣滆�� + gc.setAuthor("yyq"); + // 鏄惁鎵撳紑杈撳嚭鐩綍 榛樿涓簍rue + gc.setOpen(false); + // 瀹炰綋灞炴�� Swagger2 娉ㄨВ + gc.setSwagger2(true); + + // 鑷畾涔夋枃浠跺懡鍚嶏紝娉ㄦ剰 %s 浼氳嚜鍔ㄥ~鍏呰〃瀹炰綋灞炴�э紒 + gc.setControllerName("%sController"); + gc.setServiceName("%sService"); + gc.setServiceImplName("%sServiceImpl"); + gc.setMapperName("%sDao"); + gc.setEntityName("%sEntity"); + mpg.setGlobalConfig(gc); + + // 鏁版嵁婧愰厤缃� + DataSourceConfig dsc = new DataSourceConfig(); + // dsc.setSchemaName("public"); + dsc.setUrl(jdbc); + dsc.setDriverName(driverName); + dsc.setUsername(username); + dsc.setPassword(password); + mpg.setDataSource(dsc); + + // 璁剧疆鍖呭悕 + PackageConfig pc = new PackageConfig(); + // 鐢ㄤ簬鍖呭悕銆佽〃鍚嶅墠缂� + //pc.setModuleName(moduleName); + // 鐢熸垚鍒伴偅浜涘寘涓� 濡� com.modules涓诲寘涓嬬殑 controller.sys.TestController + pc.setParent("com.canadames"); + pc.setController("controller."+moduleName); + pc.setService("service."+moduleName); + pc.setServiceImpl("service."+moduleName+".impl"); + pc.setMapper("mapper."+moduleName); + pc.setEntity("entity."+moduleName); + mpg.setPackageInfo(pc); + + // 鑷畾涔夐厤缃� + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + // to do nothing + } + }; + + // 濡傛灉妯℃澘寮曟搸鏄� freemarker + String templatePath = "/templates/mapper.xml.ftl"; + // 濡傛灉妯℃澘寮曟搸鏄� velocity + // String templatePath = "/templates/mapper.xml.vm"; + + // 鑷畾涔夎緭鍑洪厤缃� + List<FileOutConfig> focList = new ArrayList<>(); + // 鑷畾涔夐厤缃細琚紭鍏堣緭鍑� + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 鑷畾涔夎緭鍑烘枃浠跺悕 锛� 濡傛灉浣� Entity 璁剧疆浜嗗墠鍚庣紑銆佹澶勬敞鎰� xml 鐨勫悕绉颁細璺熺潃鍙戠敓鍙樺寲锛侊紒 + return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; + } + }); + /* + cfg.setFileCreate(new IFileCreate() { + @Override + public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) { + // 鍒ゆ柇鑷畾涔夋枃浠跺す鏄惁闇�瑕佸垱寤� + checkDir("璋冪敤榛樿鏂规硶鍒涘缓鐨勭洰褰曪紝鑷畾涔夌洰褰曠敤"); + if (fileType == FileType.MAPPER) { + // 宸茬粡鐢熸垚 mapper 鏂囦欢鍒ゆ柇瀛樺湪锛屼笉鎯抽噸鏂扮敓鎴愯繑鍥� false + return !new File(filePath).exists(); + } + // 鍏佽鐢熸垚妯℃澘鏂囦欢 + return true; + } + }); + */ + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + + // 閰嶇疆妯℃澘 + TemplateConfig templateConfig = new TemplateConfig(); + + // 閰嶇疆鑷畾涔夎緭鍑烘ā鏉� + //鎸囧畾鑷畾涔夋ā鏉胯矾寰勶紝娉ㄦ剰涓嶈甯︿笂.ftl/.vm, 浼氭牴鎹娇鐢ㄧ殑妯℃澘寮曟搸鑷姩璇嗗埆 + // templateConfig.setEntity("templates/entity2.java"); + // templateConfig.setService(); + // templateConfig.setController(); + + templateConfig.setXml(null); + mpg.setTemplate(templateConfig); + + // 绛栫暐閰嶇疆 + StrategyConfig strategy = new StrategyConfig(); + + //闇�瑕佺敓鎴愮殑琛� + strategy.setInclude(tables); + strategy.setControllerMappingHyphenStyle(true); + //绫诲悕鐢熸垚绛栫暐锛氶┘宄板懡鍚� + strategy.setNaming(NamingStrategy.underline_to_camel); + //瀛楁鍚嶇敓鎴愭柟寮忥細椹煎嘲鍛藉悕 + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + // 琛ㄥ墠缂� + strategy.setTablePrefix(beginName+"_"); + + // 鍐欎簬鐖剁被涓殑鍏叡瀛楁锛堝湪鐖剁被涓凡缁忔湁鐨勪笉闇�瑕佺敓鎴愮殑瀛楁锛� + strategy.setSuperEntityColumns("id", "updateTime", "createTime"); + // 姣忓眰鐨勭户鎵匡紙涓嶉渶瑕佸彲涓嶈缃級 +// strategy.setSuperControllerClass("com.common.controller.MyController"); + strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService"); + strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl"); + strategy.setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper"); + //缁ф壙鐨勫睘鎬х埗绫� +// strategy.setSuperEntityClass("com.common.entity.MyEntity"); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + + mpg.setStrategy(strategy); + + mpg.setTemplateEngine(new FreemarkerTemplateEngine()); + + mpg.execute(); + } + + + +} + -- Gitblit v1.8.0