今天又开始写业务代码了,每次修改SQL都要重启服务,实在是浪费时间。

想起之前研究过的《mybatis plus3.1.0 热加载mapper》,一直没有成功,今天静下心来分析了问题,终于找到原因了。

上文中提到的MybatisPlusConfig,断点分析到获取资源文件未0个,不对劲。

resources = resourceResolver.getResources(mapperLocations)

于是我发现我的本地配置可能不是很好。改了一下:

mybatis-plus:
mapper-locations: classpath:/mybatis/mapper/*-mapper.xml,/mybatis/mapper/*/*Mapping.xml

改为如下

mybatis-plus:
mapper-locations: classpath*:mybatis/mapper/*/*.xml

后面加载到资源文件了,可是又遇到了另外的坑,文章中的MybatisMapperRefresh类,明明定义了集合类型,可还是有其他类型的对象在,然后就报类型转换的错误。我想到了用迭代来做转换,终于成功了。

Collection<MappedStatement> mappedStatements = configuration.getMappedStatements();
这里居然存在org.apache.ibatis.session.Configuration$StrictMap$Ambiguity,然后转换到MappedStatement对象就报类型转换的错误了。用下框红字的办法解决了。
    private void cleanKeyGenerators(List<XNode> list, String namespace) {
for (XNode context : list) {
String id = context.getStringAttribute("id");
configuration.getKeyGeneratorNames().remove(id + SelectKeyGenerator.SELECT_KEY_SUFFIX);
configuration.getKeyGeneratorNames().remove(namespace + "." + id + SelectKeyGenerator.SELECT_KEY_SUFFIX); Collection<MappedStatement> mappedStatements = configuration.getMappedStatements();
List<MappedStatement> objects = Lists.newArrayList();
Iterator<MappedStatement> it = mappedStatements.iterator();
while (it.hasNext()){
Object object=it.next();
if(object instanceof org.apache.ibatis.mapping.MappedStatement) {
MappedStatement mappedStatement=(MappedStatement)object;
if (mappedStatement.getId().equals(namespace + "." + id)) {
objects.add(mappedStatement);
}
}
}
// for (MappedStatement mappedStatement : mappedStatements) {
// if (mappedStatement.getId().equals(namespace + "." + id)) {
// objects.add(mappedStatement);
// }
// }
mappedStatements.removeAll(objects);
}
}

然后这样起作用了。

之前还研究了一篇文章,说是用idea插件模式进行,不过启动了之后,报错了,于是也没有深入。还是用代码方式好一点。

不过倒是get了很多新姿势。

https://githuboy.online/2019/05/11/基于JRebel开发的MybatisPlus热加载插件/

mybatis plus3.1.0 热加载mapper的更多相关文章

  1. Mybatis热加载Mapper.xml

    开发的时候,写Mybatis Mapper.xml文件的时候,每次修改SQL都需要重启服务,感觉十分麻烦,于是尝试写了一个Mybatis的Mapper.xml热加载. 能在修改Mapper.xml之后 ...

  2. mybatis热加载的实现

    最近在使用mybatis,由于是刚刚开始用,用的并不顺手,目前是感觉有2个地方非常的不好用: 1.mybatis调试不方便 由于dao层只有接口,实现只是一个map的xml文件,想加断点都没有地方加, ...

  3. (转)mybatis热加载(依赖mybatis-plus插件)的实现

    最近在使用mybatis,由于是刚刚开始用,用的并不顺手,目前是感觉有2个地方非常的不好用: 1.mybatis调试不方便 由于dao层只有接口,实现只是一个map的xml文件,想加断点都没有地方加, ...

  4. DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载  吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...

  5. DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载    系列目录连接 DB数据源之Spr ...

  6. 在mybatis 中批量加载mapper.xml

    可以直接加载一个包文件名,将这个包里的所有*mapper.xml文件加载进来. 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载: 必须按一定的标准:即xml文件和 ...

  7. 抛开 Spring ,你知道 MyBatis 加载 Mapper 的底层原理吗?

    原文链接:抛开 Spring ,你知道 MyBatis 加载 Mapper 的底层原理吗? 大家都知道,利用 Spring 整合 MyBatis,我们可以直接利用 @MapperScan 注解或者 @ ...

  8. 精尽MyBatis源码分析 - MyBatis初始化(二)之加载Mapper接口与XML映射文件

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  9. Mybatis源码解读-配置加载和Mapper的生成

    问题 Mybatis四大对象的创建顺序? Mybatis插件的执行顺序? 工程创建 环境:Mybatis(3.5.9) mybatis-demo,参考官方文档 简单示例 这里只放出main方法的示例, ...

随机推荐

  1. python第二天 : 计算机基础(二)

    目录 1.什么是编程 2.操作系统有什么用? 3.计算机由哪三大部分组成? 4.简述操作系统和应用程序的启动流程? 5.编程语言的分类有哪些?并评估各个分类的优缺点. 1).机器语言 2).汇编语言 ...

  2. python学习笔记10--协程、IO、IO多路复用

    本节内容 一.协程 1.1.协程概念 1.2.greenlet 1.3.Gevent 1.4.协程之爬虫 1.5.协程之socket 二.论事件驱动与异步IO 三.IO 3.1.概念说明 3.2.IO ...

  3. 前端如何实现图片懒加载(lazyload) 提高用户体验

    定义 图片懒加载又称图片延时加载.惰性加载,即在用户需要使用图片的时候加载,这样可以减少请求,节省带宽,提高页面加载速度,相对的,也能减少服务器压力. 惰性加载是程序人性化的一种体现,提高用户体验,防 ...

  4. Python datetime对象的方法

  5. 【水滴石穿】bstmy-blend-app

    这个项目是一个简单的底部导航切换页面 项目的地址为:https://github.com/Bstmy/bstmy-blend-app 先看效果 点击首页是首页面,点击个人中心是个人中心页面 先看代码 ...

  6. span元素和div元素的浮动效果

    首先看一段代码: <style> #right {margin: 10px;float:right;color:red;} #left {float:left;color:blue;} & ...

  7. Sublime text2 常用插件

    很早就安装了这款软件,因为听说很NB.但是一直都是习惯用vim, 所以一直没有去学习它, 现在用用感觉确实很不错,所以找了些插件, 参考网址: http://www.hphq.net/Marketin ...

  8. 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程(一)(2019-08-23)

    目录 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程 安装前准备 安装 ESP8266 工具链 下载 ESP8266 SDK 编译 花絮 使用 Windo ...

  9. Notepad++中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level

    使用Notepad++编辑python代码运行遇到了这个问题: IndentationError: unindent does not match any outer indentation leve ...

  10. JAVA中this的三种用法的详解

    this关键字必须放在非静态方法里面 this关键字代表自身,在程序中主要的使用用途有以下几个方面: ? 使用this关键字引用成员变量 ? 使用this关键字在自身构造方法内部引用其它构造方法 ? ...