mybatis-plus怎么自动生成类
发表于:2025-02-22 作者:千家信息网编辑
千家信息网最后更新 2025年02月22日,本篇内容介绍了"mybatis-plus怎么自动生成类"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
千家信息网最后更新 2025年02月22日mybatis-plus怎么自动生成类
本篇内容介绍了"mybatis-plus怎么自动生成类"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
目录
pom 依赖
执行sql
demo
pom.xml
org.springframework.boot spring-boot-starter-web com.baomidou mybatis-plus-generator 3.1.2 mysql mysql-connector-java 8.0.11 org.apache.velocity velocity-engine-core 2.0 org.projectlombok lombok 1.18.8
执行sql
CREATE TABLE if not exists `tbl_product_category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category_pic_code` varchar(100) NOT NULL comment '图片地址id', `name` varchar(255) NOT NULL comment '产品类别名字', `status` bit(1) NOT NULL default 1 comment '0 无效 1有效', `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 comment='产品类别信息';
执行代码
public static void main(String[] args) { String projectPath = System.getProperty("user.dir"); String outputDir = projectPath + "/src/main/java"; //生成文件输出目录 String author = "duanlsh"; //注释作者 String entity = "ProductCategory"; //生成文件实体名称 String entityPrefix = "tbl_"; //前缀 String[] tableName = "tbl_product_category".split(","); //表名多个以 , 分割 String packageName = "com.apple"; //生成文件的 包名 //数据库 String dbUrl = "jdbc:mysql://localhost:3306/grainfull?characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.cj.jdbc.Driver"); GlobalConfig config = new GlobalConfig(); config.setAuthor(author); config.setOutputDir(outputDir); config.setFileOverride(true); config.setOpen(false); //文件生成完是否打开目录 config.setEntityName("%sModel");//实体类添加Model config.setServiceName("%sService"); config.setControllerName("%sController"); config.setServiceImplName("%sServiceImpl"); config.setMapperName("%sMapper"); config.setXmlName("%sMapper"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(true) //设置是否使用 lombook// .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setColumnNaming(NamingStrategy.underline_to_camel) .setRestControllerStyle(true) .setControllerMappingHyphenStyle(true)// .setSuperEntityClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl")// .setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper") .setInclude(tableName)//修改替换成你需要的表名,多个表名传数组 .setTablePrefix(entityPrefix) ; InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { //do nothing } }; PackageConfig packageConfig = new PackageConfig();// packageConfig.setModuleName("ProductCategory"); //在parent包下面添加的包名 eg: com.apple.ProductCategory packageConfig.setParent(packageName); packageConfig.setController("controller"); packageConfig.setService("service"); packageConfig.setServiceImpl("service.impl"); packageConfig.setEntity("model");// TemplateConfig templateConfig = new TemplateConfig();// templateConfig.setEntity("/templates/entity2.java");// templateConfig.setXml(null); AutoGenerator mpg = new AutoGenerator();// mpg.setTemplate(templateConfig); mpg.setGlobalConfig(config); mpg.setDataSource(dataSourceConfig); mpg.setStrategy(strategyConfig); mpg.setCfg(cfg); mpg.setPackageInfo(packageConfig); mpg.execute(); }
"mybatis-plus怎么自动生成类"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
生成
文件
目录
自动生成
产品
内容
多个
实体
更多
知识
类别
输出
实用
有效
学有所成
接下来
代码
作者
信息
前缀
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
阿里云虚拟网络技术专家
2020村网络安全宣传总结
如何进行b s软件开发
服务器埋入地下
其他帐号微信聊天数据库
租用数据库
汉高数据库
关于战争的数据库
应用程序部署在服务器
两个数据库同步百度经验
网络安全基础 公开课
网络安全技术术语
软件开发生产效率低
中小学网络安全ppt内容
银行软件开发岗可转业务吗
oracle 数据库原理
快贷一直服务器错误
滁州塑合型服务器厂家
网络安全知识去哪学
网络安全企业大数据反诈骗
陨食互联网科技
独家述评网络安全靠人民
h2数据库数量级
我的世界服务器联机怎么保存
对数据库了解多少
重庆新中和软件开发公司咋样
常委会研究 网络安全工作
泉州视频社交软件开发
三级网络技术难点知识
语音聊天软件开发哪家好推荐