博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MyBatis-Plus 实体entity自动生成器
阅读量:3947 次
发布时间:2019-05-24

本文共 2643 字,大约阅读时间需要 8 分钟。

话不多说,直接上代码运行

// 1、创建代码生成器//        AutoGenerator mpg = new AutoGenerator();        AutoGenerator mpg = new AutoGenerator();        // 2、全局配置        GlobalConfig gc = new GlobalConfig();        String projectPath = System.getProperty("user.dir");        System.out.println(projectPath);        gc.setOutputDir(projectPath + "/src/main/java");        gc.setAuthor("dong");        gc.setOpen(false); //生成后是否打开资源管理器        gc.setFileOverride(false); //重新生成时文件是否覆盖        gc.setServiceName("%sService");	//去掉Service接口的首字母I        gc.setIdType(IdType.ID_WORKER); //主键策略        gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型        gc.setSwagger2(true);//开启Swagger2模式        mpg.setGlobalConfig(gc);        // 3、数据源配置        DataSourceConfig dsc = new DataSourceConfig();        dsc.setUrl("jdbc:mysql://localhost:3306/newsdb?serverTimezone=GMT%2B8");        dsc.setDriverName("com.mysql.cj.jdbc.Driver");        dsc.setUsername("root");        dsc.setPassword("1234566");        dsc.setDbType(DbType.MYSQL);        mpg.setDataSource(dsc);        // 4、包配置 com.dong.eduService        PackageConfig pc = new PackageConfig();        pc.setParent("com.dong");        pc.setModuleName("eduService"); //模块名        pc.setController("controller");        pc.setEntity("entity");        pc.setService("service");        pc.setMapper("mapper");        mpg.setPackageInfo(pc);        // 5、策略配置        StrategyConfig strategy = new StrategyConfig();        strategy.setInclude("User","TheOrder","Shopping","OrderState","Merchants","Food","DetailedTheOrder");        strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略        strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略        strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作        strategy.setRestControllerStyle(true); //restful api风格控制器        strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符        mpg.setStrategy(strategy);        // 6、执行        mpg.execute();
com.baomidou
mybatis-plus-boot-starter
3.0.5
org.springframework.boot
spring-boot-starter-velocity
1.4.7.RELEASE
org.apache.velocity
velocity-engine-core
2.0
org.apache.velocity
velocity-tools
2.0

转载地址:http://utiwi.baihongyu.com/

你可能感兴趣的文章
Linux rz和sz命令详解
查看>>
Python 集合set
查看>>
Codeforces Round #400 (Div. 1 + Div. 2, combined)D - The Door Problem(2-sat)
查看>>
IDEA中Struts2文件上传时404错误The origin server did not find a current representation for the target resour
查看>>
Perl/Tk 变量追踪及类线程实现
查看>>
1.嵌入式开发环境搭建--虚拟机安装(unbutu)系统
查看>>
2.嵌入式开发环境搭建--(unbutu)系统
查看>>
Linux USB驱动分析之USB2.0协议分析
查看>>
关于iwpriv :no private ioctls 的问题
查看>>
SQL Server Union等操作时解决不同数据库字符集冲突的问题
查看>>
Linq GroupJoin(二)
查看>>
递归:访问页面的控件或文件夹的下文件
查看>>
DataGridView分頁控件
查看>>
Linq 使用entity framework查询视图返回重复记录的问题(转)
查看>>
项目中得到执行文件版本或其它信息
查看>>
WinForm DatagridView绑定大量数据卡顿的问题
查看>>
DataGridView或 DataTable导出到excel
查看>>
Ilist To DataTable
查看>>
SQL @@IDENTITY, IDENT_CURRENT,SCOPE_IDENTITY
查看>>
簡單工廠模式
查看>>