zoukankan      html  css  js  c++  java
  • mybatis plus3.1.0 热加载mapper

    今天又开始写业务代码了,每次修改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热加载插件/

  • 相关阅读:
    一个不确定内容的数组,统计每个元素出现的次数的方法
    WebStorm配置TSLint
    angualr 项目环境搭建
    angular6 导出json数据到excal表
    angular6 引用echart第一次数据不显示解决
    angular6 开发实践基础知识汇总
    angular6实现对象转换数组对象
    angular 实现左侧和顶部固定定位布局
    ASP.NET MVC 全局异常
    IOC容器之Autofac
  • 原文地址:https://www.cnblogs.com/luodengxiong/p/11342292.html
Copyright © 2011-2022 走看看