SpringBoot系列(三)MybatisGenerator自动生成Mapper文件

SpringBoot系列(三)MybatisGenerator自动生成Mapper文件

2023年7月24日发(作者:)

SpringBoot系列(三)MybatisGenerator⾃动⽣成Mapper⽂件习惯于⽤ JPA 的⼈切换到 Mybatis 最痛苦的事⼉莫过于要写好多基础的增删改查语句,⽽且还不⽌⼀次。显然 Mybatis 也意识到了这⼀点,因此以⼀种相对简单粗暴地⽅式解决了这个问题,那就是我们今天要说的

Mybatis Generator需要引⼊的 Jar 包这⾥的数据库驱动版本可以⾃⾏选择,我这⾥的版本为 spring boot 2.1.7 默认版本 s mybatis 3.5.2 mysql mysql-connector-java 8.0.17 runtime tor mybatis-generator-core 1.3.7 数据库配置ties ⽂件Class==jdbc:mysql://localhost:3306/v_distribution?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/me=rd=rootMybatis Generator 配置 ⽂件

启动类代码package e;import sGenerator;import uration;import urationParser;import tShellCallback;import tream;import ist;import ;public class GeneratorMapper { public static void main(String[] args) throws Exception { //MBG 执⾏过程中的警告信息 List warnings = new ArrayList<>(); //读取配置⽂件 InputStream is = ourceAsStream("/"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = onfiguration(is); (); //当⽣成的代码重复时,覆盖原代码 DefaultShellCallback callback = new DefaultShellCallback(); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); //执⾏⽣成代码 te(null); //输出警告信息 for (String warning : warnings) { n(warning); } }}当前⽬录结构运⾏程序,⽣成mapper⽂件及实体类

发布者:admin,转转请注明出处:http://www.yc00.com/news/1690195149a312900.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信