com.baomidou.mybatisplus.annotation.DbType Java Examples
The following examples show how to use
com.baomidou.mybatisplus.annotation.DbType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenerateController.java From open-cloud with MIT License | 6 votes |
/** * 获取所有表信息 * * @return */ @ApiOperation(value = "获取所有表信息", notes = "获取所有表信息") @PostMapping("/tables") public ResultBody<List<TableInfo>> tables( @RequestParam(value = "type") String type, @RequestParam(value = "driverName") String driverName, @RequestParam(value = "url") String url, @RequestParam(value = "username") String username, @RequestParam(value = "password") String password ) { GlobalConfig gc = new GlobalConfig(); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.getDbType(type)); dsc.setDriverName(driverName); dsc.setUrl(url); dsc.setUsername(username); dsc.setPassword(password); StrategyConfig strategy = new StrategyConfig(); TemplateConfig templateConfig = new TemplateConfig(); ConfigBuilder config = new ConfigBuilder(new PackageConfig(), dsc, strategy, templateConfig, gc); List<TableInfo> list = config.getTableInfoList(); return ResultBody.ok().data(list); }
Example #2
Source File: GenerateController.java From open-cloud with MIT License | 5 votes |
@ApiOperation(value = "代码生成并下载", notes = "代码生成并下载") @PostMapping("/execute") public ResultBody<List<TableInfo>> execute( @RequestParam(value = "type") String type, @RequestParam(value = "driverName") String driverName, @RequestParam(value = "url") String url, @RequestParam(value = "username") String username, @RequestParam(value = "password") String password, @RequestParam(value = "author") String author, @RequestParam(value = "parentPackage") String parentPackage, @RequestParam(value = "moduleName") String moduleName, @RequestParam(value = "includeTables") String includeTables, @RequestParam(value = "tablePrefix") String tablePrefix ) throws Exception { String outputDir = System.getProperty("user.dir") + File.separator + "temp" + File.separator + "generator" + File.separator + DateUtils.getCurrentTimestampStr(); GenerateConfig config = new GenerateConfig(); config.setDbType(DbType.getDbType(type)); config.setJdbcUrl(url); config.setJdbcUserName(username); config.setJdbcPassword(password); config.setJdbcDriver(driverName); config.setAuthor(author); config.setParentPackage(parentPackage); config.setModuleName(moduleName); config.setIncludeTables(includeTables.split(",")); config.setTablePrefix(tablePrefix.split(",")); config.setOutputDir(outputDir); GeneratorService.execute(config); String fileName = moduleName + ".zip"; String filePath = outputDir + File.separator + fileName; // 压缩目录 String[] srcDir = {outputDir + File.separator + (parentPackage.substring(0, parentPackage.indexOf(".")))}; ZipUtil.toZip(srcDir, filePath, true); Map data = Maps.newHashMap(); data.put("filePath", filePath); data.put("fileName", fileName); return ResultBody.ok().data(data); }
Example #3
Source File: OrmConfig.java From v-mock with MIT License | 5 votes |
/** * 适配pagehelper代码 */ @Bean public PageInterceptor paginationInterceptor() { PageInterceptor pageInterceptor = new PageInterceptor(); Properties properties = new Properties(); properties.setProperty("reasonable", "true"); properties.setProperty("helperDialect", DbType.SQLITE.getDb()); properties.setProperty("supportMethodsArguments", "true"); properties.setProperty("params", "count=countSql"); pageInterceptor.setProperties(properties); return pageInterceptor; }
Example #4
Source File: SysCodeServiceImpl.java From pre with GNU General Public License v3.0 | 5 votes |
@Override public boolean generatorCode(CodeGenConfig codeGenConfig) { DataSourceConfig dataSourceConfig = new DataSourceConfig() .setDbType(DbType.MYSQL) .setUrl(url) .setUsername(username) .setPassword(password) .setDriverName(driverName); CodeGenUtil codeGenUtil = new CodeGenUtil(); codeGenUtil.generateByTables(dataSourceConfig, codeGenConfig.getPackageName(), codeGenConfig.getAuthor(), codeGenConfig.getModuleName(), codeGenConfig.getTableName()); return true; }
Example #5
Source File: CodeGenUtil.java From pre with GNU General Public License v3.0 | 5 votes |
/** * 配置数据源 * * @return 数据源配置 DataSourceConfig */ private DataSourceConfig getDataSourceConfig() { String dbUrl = "jdbc:mysql://127.0.0.1:3306/pre"; return new DataSourceConfig() .setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver"); }
Example #6
Source File: MyBatisPlusGenerator.java From SpringBootLearn with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // 代码生成器 AutoGenerator mpg = new AutoGenerator(); //1. 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("/Volumes/李浩东的移动硬盘/LiHaodong/springboot-security/src/main/java"); gc.setOpen(false); gc.setFileOverride(true); gc.setBaseResultMap(true);//生成基本的resultMap gc.setBaseColumnList(false);//生成基本的SQL片段 gc.setAuthor("lihaodong");// 作者 mpg.setGlobalConfig(gc); //2. 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("root"); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test"); mpg.setDataSource(dsc); //3. 策略配置globalConfiguration中 StrategyConfig strategy = new StrategyConfig(); strategy.setTablePrefix("");// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setSuperEntityClass("com.li.springbootsecurity.model"); strategy.setInclude("role"); // 需要生成的表 strategy.setEntityLombokModel(true); strategy.setRestControllerStyle(true); strategy.setControllerMappingHyphenStyle(true); mpg.setStrategy(strategy); //4. 包名策略配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.li.springbootsecurity"); pc.setEntity("model"); mpg.setPackageInfo(pc); // 执行生成 mpg.execute(); }
Example #7
Source File: SpringBootPlusGenerator.java From spring-boot-plus with Apache License 2.0 | 4 votes |
/** * 生成代码 * @param args */ public static void main(String[] args) { GeneratorProperties generatorProperties = new GeneratorProperties(); // 设置基本信息 generatorProperties .setMavenModuleName("example") .setParentPackage("com.example") .setModuleName("foobar") .setAuthor("geekidea") .setFileOverride(true); // 设置表信息 generatorProperties.addTable("foo_bar","id"); // 设置表前缀 // generatorProperties.setTablePrefix(Arrays.asList("tb_")); // 数据源配置 generatorProperties.getDataSourceConfig() .setDbType(DbType.MYSQL) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver") .setUrl("jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false"); // 生成配置 generatorProperties.getGeneratorConfig() .setGeneratorStrategy(GeneratorStrategy.SINGLE) .setGeneratorEntity(true) .setGeneratorController(true) .setGeneratorService(true) .setGeneratorServiceImpl(true) .setGeneratorMapper(true) .setGeneratorMapperXml(true) .setGeneratorPageParam(true) .setGeneratorQueryVo(true) .setRequiresPermissions(false) .setPageListOrder(true) .setParamValidation(true) .setSwaggerTags(true) .setOperationLog(true); // 全局配置 generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig() .setOpen(true) .setSwagger2(true) .setIdType(IdType.AUTO) .setDateType(DateType.ONLY_DATE); // 策略配置 generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig() .setNaming(NamingStrategy.underline_to_camel) .setColumnNaming(NamingStrategy.underline_to_camel) .setEntityLombokModel(true) .setRestControllerStyle(true) .setControllerMappingHyphenStyle(true) .setVersionFieldName(GeneratorConstant.VERSION) .setLogicDeleteFieldName(GeneratorConstant.DELETED); // 生成代码 CodeGenerator codeGenerator = new CodeGenerator(); codeGenerator.generator(generatorProperties); }
Example #8
Source File: CodeGenerator.java From kvf-admin with MIT License | 4 votes |
private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL).setUrl(dbUrl).setUsername(dbUsername).setPassword(dbPassword) .setDriverName("com.mysql.jdbc.Driver").setTypeConvert((globalConfig, s) -> { if (s.contains("tinyint(1)")) { // 自定义数据库表字段类型转换 return DbColumnType.INTEGER; } return new MySqlTypeConvert().processTypeConvert(globalConfig, s); }); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(true) // .setDbColumnUnderline(true) .setTablePrefix(tablePrefix) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames)//修改替换成你需要的表名,多个表名传数组 .setRestControllerStyle(true) .setSuperEntityClass("com.kalvin.kvf.common.entity.BaseEntity") .setSuperControllerClass("com.kalvin.kvf.common.controller.BaseController"); config.setActiveRecord(false) .setAuthor(author) .setOutputDir(outputDir) .setFileOverride(true) .setEnableCache(false) .setBaseResultMap(true) .setBaseColumnList(true); TemplateConfig tc = new TemplateConfig(); if (!serviceNameStartWithI) { config.setServiceName("%sService"); config.setMapperName("%sMapper"); } new AutoGenerator().setGlobalConfig(config) .setTemplate(tc) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) .setEntity("entity.sys") .setMapper("mapper.sys") .setController("controller.sys") .setService("service.sys") .setServiceImpl("service.sys") .setXml("xml.sys") ).execute(); }
Example #9
Source File: BladeCodeGenerator.java From blade-tool with GNU Lesser General Public License v3.0 | 4 votes |
public void run() { Properties props = getProperties(); AutoGenerator mpg = new AutoGenerator(); GlobalConfig gc = new GlobalConfig(); String outputDir = getOutputDir(); String author = props.getProperty("author"); gc.setOutputDir(outputDir); gc.setAuthor(author); gc.setFileOverride(true); gc.setOpen(false); gc.setActiveRecord(false); gc.setEnableCache(false); gc.setBaseResultMap(true); gc.setBaseColumnList(true); gc.setMapperName("%sMapper"); gc.setXmlName("%sMapper"); gc.setServiceName("I%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setControllerName("%sController"); gc.setSwagger2(isSwagger2); mpg.setGlobalConfig(gc); DataSourceConfig dsc = new DataSourceConfig(); String driverName = Func.toStr(this.driverName, props.getProperty("spring.datasource.driver-class-name")); if (StringUtil.containsAny(driverName, DbType.MYSQL.getDb())) { dsc.setDbType(DbType.MYSQL); dsc.setTypeConvert(new MySqlTypeConvert()); } else if (StringUtil.containsAny(driverName, DbType.POSTGRE_SQL.getDb())) { dsc.setDbType(DbType.POSTGRE_SQL); dsc.setTypeConvert(new PostgreSqlTypeConvert()); } else { dsc.setDbType(DbType.ORACLE); dsc.setTypeConvert(new OracleTypeConvert()); } dsc.setDriverName(driverName); dsc.setUrl(Func.toStr(this.url, props.getProperty("spring.datasource.url"))); dsc.setUsername(Func.toStr(this.username, props.getProperty("spring.datasource.username"))); dsc.setPassword(Func.toStr(this.password, props.getProperty("spring.datasource.password"))); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); // strategy.setCapitalMode(true);// 全局大写命名 // strategy.setDbColumnUnderline(true);//全局下划线命名 strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setTablePrefix(tablePrefix); if (includeTables.length > 0) { strategy.setInclude(includeTables); } if (excludeTables.length > 0) { strategy.setExclude(excludeTables); } if (hasSuperEntity) { strategy.setSuperEntityClass("org.springblade.core.mp.base.BaseEntity"); strategy.setSuperEntityColumns(superEntityColumns); strategy.setSuperServiceClass("org.springblade.core.mp.base.BaseService"); strategy.setSuperServiceImplClass("org.springblade.core.mp.base.BaseServiceImpl"); } else { strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService"); strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl"); } // 自定义 controller 父类 strategy.setSuperControllerClass("org.springblade.core.boot.ctrl.BladeController"); strategy.setEntityBuilderModel(false); strategy.setEntityLombokModel(true); strategy.setControllerMappingHyphenStyle(true); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); // 控制台扫描 pc.setModuleName(null); pc.setParent(packageName); pc.setController("controller"); pc.setEntity("entity"); pc.setXml("mapper"); mpg.setPackageInfo(pc); mpg.setCfg(getInjectionConfig()); mpg.execute(); }
Example #10
Source File: CodeGeneration.java From poseidon with Apache License 2.0 | 4 votes |
public static void main(String[] args) { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir( "/media/code/program/java/poseidon/poseidon/psd-web-view/src/main/java"); gc.setFileOverride(true); gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("yoke");// 作者 // 自定义文件命名,注意 %s 会自动填充表实体属性! gc.setControllerName("%sController"); gc.setServiceName("%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setMapperName("%sMapper"); gc.setXmlName("%sMapper"); mpg.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("FJEOIRFWQ132EW"); dsc.setUrl( "jdbc:mysql://www.test.com:13306/poseidon?useUnicode=true&characterEncoding=utf-8&useSSL=false"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); strategy.setTablePrefix("db_");// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude("db_item_attribute_name", "db_item_attribute_value", "db_item_sku"); strategy.setSuperServiceClass(null); strategy.setSuperServiceImplClass(null); strategy.setSuperMapperClass(null); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.yoke.poseidon.web.itemShow"); pc.setController("web"); pc.setService("service"); pc.setServiceImpl("serviceImpl"); pc.setMapper("mapper"); pc.setEntity("entity"); pc.setXml("mapper"); mpg.setPackageInfo(pc); // 执行生成 mpg.execute(); }
Example #11
Source File: MBPlusTest.java From Resource with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) { AutoGenerator ag = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); //gc.setOutputDir("D:\\workspace\\SpringBoot\\src\\main\\java");//将代码生成在项目中 gc.setOutputDir(System.getProperty("user.dir") + "/src/main/java");//将代码生成在指定目录中 gc.setFileOverride(true); gc.setActiveRecord(false); // 不需要ActiveRecord特性的请改为false gc.setEnableCache(false); // XML 二级缓存 gc.setBaseResultMap(true); // XML ResultMap gc.setBaseColumnList(false);// XML columnList gc.setAuthor("zsm"); // 作者 gc.setDateType(DateType.ONLY_DATE);//只生成java.util.Date类型时间格式 // 自定义文件命名,注意 %s 会自动填充表实体属性 gc.setControllerName("%sController"); gc.setServiceName("%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setMapperName("%sMapper"); gc.setXmlName("%sMapper"); ag.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); //设置数据库类型 dsc.setDbType(DbType.MYSQL); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("123456"); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test_db?characterEncoding=utf-8"); ag.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); // strategy.setCapitalMode(true); // 全局大写命名 ORACLE 注意 strategy.setTablePrefix(new String[] {"tb_"}); // 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel); // 表名生成策略 strategy.setInclude(new String[] {"tb_user", "tb_order"}); // 需要生成的表 // strategy.setExclude(new String[]{"tb_test"}); // 排除生成的表 strategy.setSuperServiceClass(null); // 自定义 service 父类 strategy.setSuperServiceImplClass(null); strategy.setSuperMapperClass(null); // 自定义实体父类 //strategy.setSuperEntityClass(com.zsm.sb.entity.BaseEntity); // 自定义实体,公共字段 //strategy.setSuperEntityColumns(new String[] { "test_id", "userId" }); // 自定义 mapper 父类 // strategy.setSuperMapperClass("com.zsm.sb.mapper.BaseMapper"); // 自定义 service 父类 // strategy.setSuperServiceClass("com.zsm.sb.service.BaseService"); // 自定义 service 实现类父类 // strategy.setSuperServiceImplClass("com.zsm.sb.service.BaseServiceImpl"); // 自定义 controller 父类 // strategy.setSuperControllerClass("com.zsm.sb.controller.BaseController"); // 实体是否生成字段常量(默认 false) // public static final String ID = "userId"; // strategy.setEntityColumnConstant(true); // 实体是否为构建者模型(默认 false) // public User setName(String name) {this.name = name; return this;} //strategy.setEntityBuilderModel(true); ag.setStrategy(strategy); // 生成代码包名配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.zsm.sb"); pc.setController("controller"); pc.setService("service"); pc.setServiceImpl("service.impl"); pc.setMapper("dao"); pc.setEntity("model"); pc.setXml("mapper"); ag.setPackageInfo(pc); // 自定义 xxList.jsp 生成 List<FileOutConfig> focList = new ArrayList<FileOutConfig>(); // focList.add(new FileOutConfig("/template/list.jsp.vm") { // @Override // public String outputFile(TableInfo tableInfo) { // // 自定义输入文件名称 // return "D://my_" + tableInfo.getEntityName() + ".jsp"; // } // }); // cfg.setFileOutConfigList(focList); // mpg.setCfg(cfg); // 执行生成 ag.execute(); }