如何实现Springboot版mybatis逆向生成
发表于:2026-11-04 作者:千家信息网编辑
千家信息网最后更新 2026年11月04日,这篇文章主要介绍如何实现Springboot版mybatis逆向生成,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!代码生成器逆向生成mysql对应的pojo和mybatis通过
千家信息网最后更新 2026年11月04日如何实现Springboot版mybatis逆向生成
这篇文章主要介绍如何实现Springboot版mybatis逆向生成,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
代码生成器
逆向生成mysql对应的pojo和mybatis通过单独的一个工程不影响现有的业务逻辑。
mybatis-generatorConfig工程
通过源码里面的sql生成对应的表结构和表数据。

mybatis-generatorConfig的pom文件
4.0.0 com.idig8 0.0.1-SNAPSHOT mybatis-generatorConfig UTF-8 org.springframework.boot spring-boot-starter-log4j 1.3.8.RELEASE com.alibaba druid 1.1.0 com.alibaba druid-spring-boot-starter 1.1.0 mysql mysql-connector-java 5.1.41 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1 tk.mybatis mapper-spring-boot-starter 1.2.4 com.github.pagehelper pagehelper-spring-boot-starter 1.2.3 org.mybatis.generator mybatis-generator-core 1.3.2 compile true
添加generatorConfig.xml文件
GeneratorDisplay.java类
package com.idig8.mybatis.utils;import java.io.File;import java.util.ArrayList;import java.util.List;import org.mybatis.generator.api.MyBatisGenerator;import org.mybatis.generator.config.Configuration;import org.mybatis.generator.config.xml.ConfigurationParser;import org.mybatis.generator.internal.DefaultShellCallback;public class GeneratorDisplay { public void generator() throws Exception{ List warnings = new ArrayList(); boolean overwrite = true; //指定 逆向工程配置文件 File configFile = new File("generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); } public static void main(String[] args) throws Exception { try { GeneratorDisplay generatorSqlmap = new GeneratorDisplay(); generatorSqlmap.generator(); } catch (Exception e) { e.printStackTrace(); } }} 添加MyMapper.java文件
/* * The MIT License (MIT) * * Copyright (c) 2014-2016 abel533@gmail.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */package com.idig8.utils;import tk.mybatis.mapper.common.Mapper;import tk.mybatis.mapper.common.MySqlMapper;public interface MyMapperextends Mapper , MySqlMapper { //TODO //FIXME 特别注意,该接口不能被扫描到,否则会出错}
运行GeneratorDisplay的main方法
复制com.idig8.mapper目录到wx-springboot-mapper项目下
复制com.idig8.pojo 目录到wx-springboot-pojo项目下
复制com.idig8.utils 目录到wx-springboot-common项目下

复制resources mapper到wx-springboot-api的resources里面
PS:mybatis-generatorConfig 可以看成一个单独的项目,主要的目的就是为了升成对应的mapper.xml和对应的pojo实体类,mapper对应的实体。
以上是"如何实现Springboot版mybatis逆向生成"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
生成
文件
项目
工程
目录
内容
实体
篇文章
业务
代码
价值
兴趣
小伙
小伙伴
就是
接口
数据
方法
更多
源码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
深圳九邦互联网科技有限公司
互联网科技工作委员会副主任毛军
互联网是不是新科技
狮子座互联网科技
互联网科技小贷
奇酷互联网络科技公司
互联网高科技企业
深圳期待互联网科技
人人互联网科技是培训
海南购全球互联网科技
金融科技与互联网金融相同和不同
荆州市昕露互联网络科技有限公司
乌苏新华互联网科技做什么的
互联网科技的全部知识
互联网在线教育科技创业
互联网科技资金流入
新氧科技和美国互联网有关系吗
陕西九四连强互联网科技有限公司
互联网时代高科技布局
广西泛欧互联网科技有限公司
科技互联网
互联网科技公司排名
广州万易互联网科技有限公司
互联网金融 科技
碳银互联网科技
朗涯互联网科技
太原新华互联网科技学校怎么样
工业互联网山东科技大学
上海旺乐尼互联网科技有限公司
互联网高科技绘画