从 PageHelper 到 MyBatis Plugin

Mybatis三剑客(mybatis-generator、mybatis-plugin、mybatis-pagehelper)介绍、配置及破解 本文用的是maven,idea15Mabatis三剑客分别是:mybatis-generator、mybatis-plugin、mybatis-pagehelper一、mybatis-generator根据我们的数据库自动生成pojo、dao和xml文件 pojo里面放的是跟数据库字段一一对应的对象、dao层是接口,供service使用,xml是这个dao层接口的实现,sql语句都写在xml里1. 阅读详情

在很多业务场景下我们需要去拦截 SQL,达到不入侵原有代码业务处理一些东西,比如:历史记录、分页操作、数据权限过滤操作、SQL 执行时间性能监控等等,这里我们就可以用到 MyBatis 的插件 Plugin。下面我们来了解一下 Plugin 到底是如何工作的。

一、背景

使用过 MyBatis 框架的朋友们肯定都听说过 PageHelper 这个分页神器吧,其实 PageHelper 的底层实现就是依靠 plugin。下面我们来看一下 PageHelper 是如何利用 plugin 实现分页的。

二、MyBatis 执行概要图

首先我们先看一下 MyBatis 的执行流程图,对其执行流程有一个大体的认识。

三、MyBatis 核心对象介绍

从 MyBatis 代码实现的角度来看,MyBatis 的主要的核心部件有以下几个:

  • Configuration:初始化基础配置,比如 MyBatis 的别名等,一些重要的类型对象,如,插件,映射器,ObjectFactory 和 typeHandler 对象,MyBatis 所有的配置信息都维持在 Configuration 对象之中。
  • SqlSessionFactory:SqlSession 工厂,用于生产 SqlSession。
  • SqlSession: 作为 MyBatis 工作的主要顶层 API,表示和数据库交互的会话,完成必要数据库增删改查功能
  • Executor:MyBatis 执行器,是 MyBatis 调度的核心,负责 SQL 语句的生成和查询缓存的维护
  • StatementHandler:封装了 JDBC Statement 操作,负责对 JDBC Statement 的操作,如设置参数、将 Statement 结果集转换成List集合。
  • ParameterHandler:负责对用户传递的参数转换成 JDBC Statement 所需要的参数,
  • ResultSetHandler:负责将 JDBC 返回的 ResultSet 结果集对象转换成 List 类型的集合;
  • TypeHandler:负责 java 数据类型和 jdbc 数据类型之间的映射和转换
  • MappedStatement:MappedStatement 维护了一条 <select|update|delete|insert> 节点的封装,
  • SqlSource:负责根据用户传递的 parameterObject,动态地生成 SQL 语句,将信息封装到 BoundSql 对象中,并返回
  • BoundSql:表示动态生成的 SQL 语句以及相应的参数信息

说了这么多,怎么还没进入正题啊,别急,下面就开始讲解 Plugin 的实现原理。

四、Plugin 实现原理

MyBatis 支持对 Executor、StatementHandler、PameterHandler和ResultSetHandler 接口进行拦截,也就是说会对这4种对象进行代理。下面我们结合 PageHelper 来讲解 Plugin 是怎样实现的。

1、定义 Plugin

要使用自定义 Plugin 首先要实现 Interceptor 接口。可以通俗的理解为一个 Plugin 就是一个拦截器。

public interface Interceptor {
  // 实现拦截逻辑   
  Object intercept(Invocation invocation) throws Throwable;
  // 获取代理类
  Object plugin(Object target);
  // 初始化配置
  void setProperties(Properties properties);

}

现在我们来看一下 PageHelper 是如何通过 Plugin 实现分页的。

@Intercepts(
    {
        @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
        @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
    }
)
public class PageInterceptor implements Interceptor {
    //缓存count查询的ms
    protected Cache<CacheKey, MappedStatement> msCountMap = null;
    private Dialect dialect;
    private String default_dialect_class = "com.github.pagehelper.PageHelper";
    private Field additionalParametersField;

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        try {
            Object[] args = invocation.getArgs();
            MappedStatement ms = (MappedStatement) args[0];
            Object parameter = args[1];
            RowBounds rowBounds = (RowBounds) args[2];
            ResultHandler resultHandler = (ResultHandler) args[3];
            Executor executor = (Executor) invocation.getTarget();
            CacheKey cacheKey;
            BoundSql boundSql;
            //由于逻辑关系,只会进入一次
            if(args.length == 4){
                //4 个参数时
                boundSql = ms.getBoundSql(parameter);
                cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
            } else {
                //6 个参数时
                cacheKey = (CacheKey) args[4];
                boundSql = (BoundSql) args[5];
            }
            List resultList;
            //调用方法判断是否需要进行分页,如果不需要,直接返回结果
            if (!dialect.skip(ms, parameter, rowBounds)) {
                //反射获取动态参数
                Map<String, Object> additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql);
                //判断是否需要进行 count 查询
                if (dialect.beforeCount(ms, parameter, rowBounds)) {
                    //创建 count 查询的缓存 key
                    CacheKey countKey = executor.createCacheKey(ms, parameter, RowBounds.DEFAULT, boundSql);
                    countKey.update(MSUtils.COUNT);
                    MappedStatement countMs = msCountMap.get(countKey);
                    if (countMs == null) {
                        //根据当前的 ms 创建一个返回值为 Long 类型的 ms
                        countMs = MSUtils.newCountMappedStatement(ms);
                        msCountMap.put(countKey, countMs);
                    }
                    //调用方言获取 count sql
                    String countSql = dialect.getCountSql(ms, boundSql, parameter, rowBounds, countKey);
                    countKey.update(countSql);
                    BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter);
                    //当使用动态 SQL 时,可能会产生临时的参数,这些参数需要手动设置到新的 BoundSql 中
                    for (String key : additionalParameters.keySet()) {
                        countBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
                    }
                    //执行 count 查询
                    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey, countBoundSql);
                    Long count = (Long) ((List) countResultList).get(0);
                    //处理查询总数
                    //返回 true 时继续分页查询,false 时直接返回
                    if (!dialect.afterCount(count, parameter, rowBounds)) {
                        //当查询总数为 0 时,直接返回空的结果
                        return dialect.afterPage(new ArrayList(), parameter, rowBounds);
                    }
                }
                //判断是否需要进行分页查询
                if (dialect.beforePage(ms, parameter, rowBounds)) {
                    //生成分页的缓存 key
                    CacheKey pageKey = cacheKey;
                    //处理参数对象
                    parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey);
                    //调用方言获取分页 sql
                    String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey);
                    BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter);
                    //设置动态参数
                    for (String key : additionalParameters.keySet()) {
                        pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
                    }
                    //执行分页查询
                    resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql);
                } else {
                    //不执行分页的情况下,也不执行内存分页
                    resultList = executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql);
                }
            } else {
                //rowBounds用参数值,不使用分页插件处理时,仍然支持默认的内存分页
                resultList = executor.query(ms, parameter, rowBounds, resultHandler, cacheKey, boundSql);
            }
            return dialect.afterPage(resultList, parameter, rowBounds);
        } finally {
            dialect.afterAll();
        }
    }

    @Override
    public Object plugin(Object target) {
        //TODO Spring bean 方式配置时,如果没有配置属性就不会执行下面的 setProperties 方法,就不会初始化,因此考虑在这个方法中做一次判断和初始化
        //TODO https://github.com/pagehelper/Mybatis-PageHelper/issues/26
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        //缓存 count ms
        msCountMap = CacheFactory.createCache(properties.getProperty("msCountCache"), "ms", properties);
        String dialectClass = properties.getProperty("dialect");
        if (StringUtil.isEmpty(dialectClass)) {
            dialectClass = default_dialect_class;
        }
        try {
            Class<?> aClass = Class.forName(dialectClass);
            dialect = (Dialect) aClass.newInstance();
        } catch (Exception e) {
            throw new PageException(e);
        }
        dialect.setProperties(properties);
        try {
            //反射获取 BoundSql 中的 additionalParameters 属性
            additionalParametersField = BoundSql.class.getDeclaredField("additionalParameters");
            additionalParametersField.setAccessible(true);
        } catch (NoSuchFieldException e) {
            throw new PageException(e);
        }
    }

}

代码太长不看系列: 其实这段代码最主要的逻辑就是在执行 Executor 方法的时候,拦截 query 也就是查询类型的 SQL, 首先会判断它是否需要分页,如果需要分页就会根据查询参数在 SQL 末尾加上 limit pageNum, pageSize来实现分页。

2、注册拦截器

  • 通过 SqlSessionFactoryBean 去构建 Configuration 添加拦截器并构建获取 SqlSessionFactory。

public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {

    // ... 此处省略部分源码

    protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
        // ... 此处省略部分源码

        // 查看是否注入拦截器,有的话添加到Interceptor集合里面
        if (!isEmpty(this.plugins)) {
            for (Interceptor plugin : this.plugins) {
                configuration.addInterceptor(plugin);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Registered plugin: '" + plugin + "'");
                }
            }
        }

        // ... 此处省略部分源码

        return this.sqlSessionFactoryBuilder.build(configuration);
    }

    // ... 此处省略部分源码
}

  • 通过原始的 XMLConfigBuilder 构建 configuration 添加拦截器
public class XMLConfigBuilder extends BaseBuilder {
    //解析配置
    private void parseConfiguration(XNode root) {
        try {
            //省略部分代码
            pluginElement(root.evalNode("plugins"));

        } catch (Exception e) {
            throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
        }
    }

    private void pluginElement(XNode parent) throws Exception {
        if (parent != null) {
            for (XNode child : parent.getChildren()) {
                String interceptor = child.getStringAttribute("interceptor");
                Properties properties = child.getChildrenAsProperties();
                Interceptor interceptorInstance = (Interceptor) resolveClass(interceptor).newInstance();
                interceptorInstance.setProperties(properties);
                //调用InterceptorChain.addInterceptor
                configuration.addInterceptor(interceptorInstance);
            }
        }
    }
}

上面是两种不同的形式构建 configuration 并添加拦截器 interceptor,上面第二种一般是以前 XML 配置的情况,这里主要是解析配置文件的 plugin 节点,根据配置的 interceptor 属性实例化 Interceptor 对象,然后添加到 Configuration 对象中的 InterceptorChain 属性中。

如果定义多个拦截器就会它们链起来形成一个拦截器链,初始化配置文件的时候就把所有的拦截器添加到拦截器链中。

public class InterceptorChain {

  private final List<Interceptor> interceptors = new ArrayList<Interceptor>();

  public Object pluginAll(Object target) {
    //循环调用每个Interceptor.plugin方法
    for (Interceptor interceptor : interceptors) {
      target = interceptor.plugin(target);
    }
    return target;
  }
   // 添加拦截器
  public void addInterceptor(Interceptor interceptor) {
    interceptors.add(interceptor);
  }

  public List<Interceptor> getInterceptors() {
    return Collections.unmodifiableList(interceptors);
  }

}

3、执行拦截器

从以下代码可以看出 MyBatis 在实例化 Executor、ParameterHandler、ResultSetHandler、StatementHandler 四大接口对象的时候调用 interceptorChain.pluginAll() 方法插入进去的。其实就是循环执行拦截器链所有的拦截器的 plugin() 方法, MyBatis 官方推荐的 plugin 方法是 Plugin.wrap() 方法,这个就会生成代理类。


public class Configuration {

    protected final InterceptorChain interceptorChain = new InterceptorChain();
    //创建参数处理器
    public ParameterHandler newParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
        //创建ParameterHandler
        ParameterHandler parameterHandler = mappedStatement.getLang().createParameterHandler(mappedStatement, parameterObject, boundSql);
        //插件在这里插入
        parameterHandler = (ParameterHandler) interceptorChain.pluginAll(parameterHandler);
        return parameterHandler;
    }

    //创建结果集处理器
    public ResultSetHandler newResultSetHandler(Executor executor, MappedStatement mappedStatement, RowBounds rowBounds, ParameterHandler parameterHandler,
                                                ResultHandler resultHandler, BoundSql boundSql) {
        //创建DefaultResultSetHandler
        ResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, mappedStatement, parameterHandler, resultHandler, boundSql, rowBounds);
        //插件在这里插入
        resultSetHandler = (ResultSetHandler) interceptorChain.pluginAll(resultSetHandler);
        return resultSetHandler;
    }

    //创建语句处理器
    public StatementHandler newStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
        //创建路由选择语句处理器
        StatementHandler statementHandler = new RoutingStatementHandler(executor, mappedStatement, parameterObject, rowBounds, resultHandler, boundSql);
        //插件在这里插入
        statementHandler = (StatementHandler) interceptorChain.pluginAll(statementHandler);
        return statementHandler;
    }

    public Executor newExecutor(Transaction transaction) {
        return newExecutor(transaction, defaultExecutorType);
    }

    //产生执行器
    public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
        executorType = executorType == null ? defaultExecutorType : executorType;
        //这句再做一下保护,囧,防止粗心大意的人将defaultExecutorType设成null?
        executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
        Executor executor;
        //然后就是简单的3个分支,产生3种执行器BatchExecutor/ReuseExecutor/SimpleExecutor
        if (ExecutorType.BATCH == executorType) {
            executor = new BatchExecutor(this, transaction);
        } else if (ExecutorType.REUSE == executorType) {
            executor = new ReuseExecutor(this, transaction);
        } else {
            executor = new SimpleExecutor(this, transaction);
        }
        //如果要求缓存,生成另一种CachingExecutor(默认就是有缓存),装饰者模式,所以默认都是返回CachingExecutor
        if (cacheEnabled) {
            executor = new CachingExecutor(executor);
        }
        //此处调用插件,通过插件可以改变Executor行为
        executor = (Executor) interceptorChain.pluginAll(executor);
        return executor;
    }
}

4、Plugin 的动态代理

我们首先看一下Plugin.wrap() 方法,这个方法的作用是为实现Interceptor注解的接口实现类生成代理对象的。

    // 如果是Interceptor注解的接口的实现类会产生代理类 
    public static Object wrap(Object target, Interceptor interceptor) {
    //从拦截器的注解中获取拦截的类名和方法信息
    Map<Class<?>, Set<Method>> signatureMap = getSignatureMap(interceptor);
    //取得要改变行为的类(ParameterHandler|ResultSetHandler|StatementHandler|Executor)
    Class<?> type = target.getClass();
    //取得接口
    Class<?>[] interfaces = getAllInterfaces(type, signatureMap);
    //产生代理,是Interceptor注解的接口的实现类才会产生代理
    if (interfaces.length > 0) {
      return Proxy.newProxyInstance(type.getClassLoader(),interfaces,new Plugin(target, interceptor, signatureMap));
    }
    return target;
  }

Plugin 中的 getSignatureMap、 getAllInterfaces 两个辅助方法,来帮助判断是否为是否Interceptor注解的接口实现类。

  //取得签名Map,就是获取Interceptor实现类上面的注解,要拦截的是那个类(Executor 
  //,ParameterHandler, ResultSetHandler,StatementHandler)的那个方法 
private static Map<Class<?>, Set<Method>> getSignatureMap(Interceptor interceptor) {
    //取Intercepts注解
    Intercepts interceptsAnnotation =interceptor.getClass().getAnnotation(Intercepts.class);

    //必须得有Intercepts注解,没有报错
    if (interceptsAnnotation == null) {
      throw new PluginException("No @Intercepts annotation was found in interceptor " + interceptor.getClass().getName());      
    }
    //value是数组型,Signature的数组
      Signature[] sigs = interceptsAnnotation.value();
    //每个class里有多个Method需要被拦截,所以这么定义
      Map<Class<?>, Set<Method>> signatureMap = new HashMap<Class<?>, Set<Method>>();
     for (Signature sig : sigs) {
      Set<Method> methods = signatureMap.get(sig.type());
        if (methods == null) {
          methods = new HashSet<Method>();
          signatureMap.put(sig.type(), methods);
      }
      try {
         Method method = sig.type().getMethod(sig.method(), sig.args());
         methods.add(method);
      } catch (NoSuchMethodException e) {
         throw new PluginException("Could not find method on " + sig.type() + " named " + sig.method() + ". Cause: " + e, e);
      }
    }
    return signatureMap;
  }

 //取得接口
 private static Class<?>[] getAllInterfaces(Class<?> type, Map<Class<?>, Set<Method>> signatureMap) {
    Set<Class<?>> interfaces = new HashSet<Class<?>>();
      while (type != null) {
        for (Class<?> c : type.getInterfaces()) {
        //拦截其他的无效
        if (signatureMap.containsKey(c)) {
          interfaces.add(c);
        }
      }
      type = type.getSuperclass();
    }
    return interfaces.toArray(new Class<?>[interfaces.size()]);
  }
}

我们来看一下代理类的 query 方法,其实就是调用了 Plugin.invoke() 方法。代理类屏蔽了 intercept 方法的调用。

    public final List query(MappedStatement mappedStatement, Object object, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql) throws SQLException {
        try {
            // 这里的 h 就是一个 Plugin
            return (List)this.h.invoke(this, m5, new Object[]{mappedStatement, object, rowBounds, resultHandler, cacheKey, boundSql});
        }
        catch (Error | RuntimeException | SQLException throwable) {
            throw throwable;
        }
        catch (Throwable throwable) {
            throw new UndeclaredThrowableException(throwable);
        }
    }

最后 Plugin.invoke() 就是判断当前方法是否拦截,如果需要拦截则会调用 Interceptor.intercept() 对当前方法执行拦截逻辑。

public class Plugin implements InvocationHandler {

    ...
  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
      //获取需要拦截的方法
      Set<Method> methods = signatureMap.get(method.getDeclaringClass());
      //是Interceptor实现类注解的方法才会拦截处理
      if (methods != null && methods.contains(method)) {
        //调用Interceptor.intercept,即调用自己写的逻辑
        return interceptor.intercept(new Invocation(target, method, args));
      }
      //最后执行原来逻辑
        return method.invoke(target, args);
    } catch (Exception e) {
        throw ExceptionUtil.unwrapThrowable(e);
    }
  }

    ...

总结

我们以 PageHelper 为切入点讲解了 MyBatis Plugin 的实现原理,其中 MyBatis 拦截器用到责任链模式+动态代理+反射机制。 通过上面的分析可以知道,所有可能被拦截的处理类都会生成一个代理类,如果有 N 个拦截器,就会有 N 个代理,层层生成动态代理是比较耗性能的。而且虽然能指定插件拦截的位置,但这个是在执行方法时利用反射动态判断的,初始化的时候就是简单的把拦截器插入到了所有可以拦截的地方。所以尽量不要编写不必要的拦截器,并且拦截器尽量不要写复杂的逻辑。

vrep小车避障算法_V-REP 多车道巡线与避障 任务概要在给定的赛道中,实现多车道的避障和视觉巡线。避障算法没有限定,可使用人工势场、RRT等路径规划算法。车体大小、赛道信息以及参考资料在此处下载。完成情况已学习并能初步使用 V-REP Python Remote API 接口,实现 Python 与 V-REP 的功能交互。已实现基于视觉传感器的多车道巡线功能。已实现基于视觉传感器的多车道避障功能。V-REP Python Remote AP... 阅读详情

相关推荐

MobaXterm详细使用教程

当然MobaXterm的功能远不止这些,但这些是最基本,最常用的,因此先拿出来讲。点击确定后,输入密码(输入密码时并不会显示,只管输入后按确定即可,第一次登陆成功后会提示保存密码,一般选择同意),就可以连接上虚拟机了。(2) 我们可以直接apt-get安装vim等常用功能(或者官网下载插件),实现在windows下模拟linux环境,这样就可以使用vi命令准备INCAR文件,也可以使用Gnuplot进行绘图。支持 Unix 命令(bash,ls,cat,sed,grep,awk,rsync,…

博客 4万+

mybatis 拦截器拦截所有sql

package org.geekworld.core.mybatis; import com.alibaba.fastjson.JSON; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; i

wuxifu001的专栏 1万+

【Flink cdc】Data row is smaller than a column index, internal schema representation is probably xxx

翻译一下:当scan.startup.mode=EARLIEST_OFFSET时,如果在最早的offset之后表结构有过变化就无法支持。原因应该是在binlog 的earliest_offset之后,表结构被修改过。我的解决方案:source配置中使用。mysql source配置使用。,以时间戳为消费依据。

integrity 2092

mybatis-plus 拦截器敏感字段加解密

背景 数据库在保存数据时,对于某些敏感数据需要脱敏或者加密处理,如果一个一个的去加显然工作量大而且容易出错,这个时候可以考虑使用拦截器,本文针对的是mybatis-plus作为持久层框架,其他场景未测试。代码如下: 一、查询拦截器 package com.sfpay.merchant.service.interceptor; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.sfpay.merch.

u010038477的博客 5275

YOLOv8冻结层的迁移学习 全网首发

在调用时会创建trainer此时的模型配置更新了,冻结了个p。

qq_42693842的博客 6590

最小二乘法(看完即会)

其中,X是数据矩阵,每一行是一个数据点,每一列是一个自变量(包括截距项),Y是观测值向量,β是待求的系数向量。为了找到使S最小的a和b的值,我们需要对S求关于a和b的偏导数,并令它们等于零。最小二乘法的数学公式通常用于线性回归问题,其中目标是找到一条直线(或更高维度的超平面),使得这条直线与给定数据点的误差平方和最小。同样地,通过求偏导数和令偏导数等于零,我们可以得到一个线性方程组,解这个方程组可以找到最优的b_0, b_1, …+ b_m*x_m,其中b_0是截距,b_1到b_m是各个自变量的系数。

qlkaicx的博客 2万+

mybatis插件,sql生成

下面实现mybatis 插件类Interceptor 在intercept中把sql中的?转成成实际的参数 @Intercepts( { @Signature(type = org.apache.ibatis.executor.Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.cla..

tangdacheng的专栏 663

CAPL控制程控电源

汽车电子测试过程中,除了实车测试,还有台架测试,在进行台架测试时,都需要通过电源来模拟汽车电瓶给ECU供电,如果要进一步进行比较高效的压力测试或自动化测试,就需要用到程控电源,所以本章主要介绍CAPL是如何来控制程控电源的。

测试领域技术分享 4397

mybatis @Intercepts的用法2:限制sql查询数量

Interceptor

tumu6889的博客 813

关于“为爱发电”的一些说明~~

专栏教学资料+工程文件

数字IC/FPGA杂货铺,找一找,或许有你想要的~ 2684

【Linux命令大全】006.网络通讯之netstat命令(实操篇)

本文详细介绍了Linux系统中netstat网络诊断命令的实用技巧。主要内容包括:1) 基本功能与参数详解,展示如何查看网络连接、路由表和接口统计;2) 安装方法及基础用法,如查看TCP/UDP连接、显示进程信息和路由表;3) 高级应用技巧,包括监听端口检查、连接状态统计和实时监控。文章通过表格和代码示例,系统性地呈现了netstat在系统管理中的核心应用场景,是网络故障排查和性能监控的实用指南。

yuhuasheng1997的博客 712

mysql动态添加mybatis的sql执行所需要的时间

SqlStatementInterceptor.java import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.plugin.*; import or.

m0_60380027的博客 670

安装anaconda3时出现错误:Failed to link extracted packages to D:\anaconda!...如何解决?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1490

MyBatis插件的使用:mybatis-generator、mybatis-plugin、mybatis-pagehelper

使用Intellij Idea2016.3.1+Maven3.3.9。 一、mybatis-generator的使用 作用:根据数据库自动生成pojo、dao和xml文件。 1、引入mybatis-generator pom.xml中引入配置: MMall org.mybatis.generator mybatis-gen

烂笔头 5790

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

Mybatis三剑客——Mybatis-generator、Mybatis-plugin、Mybatis-pagehelper配置

1.Mybatis三剑客 Mybatis-generator 自动化生成基本的pojo、dao、mapper.xml (1). pom文件在plugins标签下添加 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-gener...

csdnLeraner的博客 488

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Mabatis三剑客分别是:mybatis-generator、mybatis-plugin、mybatis-pagehelper

本文用的是maven,idea15 Mabatis三剑客分别是:mybatis-generator、mybatis-plugin、mybatis-pagehelper 一、mybatis-generator 根据我们的数据库自动生成pojo、dao和xml文件  pojo里面放的是跟数据库字段一一对应的对象、dao层是接口,供service使用,xml是这个dao层接口的实现,

张迁的博客 8189

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Mybatis三剑客(mybatis-generotor、mybatis-plugin、mybatis-pagehelper)

     Mybatis三剑客(mybatis-generotor、mybatis-plugin、mybatis-pagehelper) mybatis-generotor 创建项目各包名 idea的安装: 在pom.xml的插件标签&lt;plugins&gt;&lt;/plugins&gt;添加 &lt;plugin&gt; &lt;groupId&gt;...

stay hungry ! stay foolish! 1310

Mybatis遇到com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

错误 Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor 问题原因 maven导入的坐标是PageHelper 5.1.X 版本

bbbefs的博客 721

Mybatis三剑客插件

上次是进行了一个定时器任务的操作,这次进行Mybatis三剑客插件的使用。 主要任务:安装Mybatis插件 Mybatis-plugin插件 步骤如下: ①Help—Eclipse Marketplace ②在搜索框中搜Mybatis,找到如下版本的插件,点击Install ③点击confirm ④选择接受 ⑤出现警告,选择OK ⑥选择Yes,重启Eclipse OK,插件我们配置...

crystallf的博客 801

Mybatis-plugin插件

Mybatis三剑客(1)-Mybatis-plugin插件 •要查找某一个方法,在dao接口中某一个方法中 按住 Ctrl键 鼠标指到方法名称上 选择open xml 就会自动跳转 • 编辑 XML 文件时自动补全,自动生成 ...

choushi2281的博客 718

mybatis->mybatis自动连接数据库生成实体和dao和xml和Example

本文用的是maven,idea15 Mabatis三剑客分别是:mybatis-generator、mybatis-plugin、mybatis-pagehelper 一、mybatis-generator 根据我们的数据库自动生成pojo、dao和xml文件  pojo里面放的是跟数据库字段一一对应的对象、dao层是接口,供service使用,xml是这个dao层接口的实现,sql语句都写...

u013291321的博客 2290

Mybatis三剑客(mybatis generator, mybaits plugin, pageHelper)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34268753的博客 110

IDEA mybatis报错com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.

mybatis配置分页助手插件时报错 原核心配置文件为 : <plugins> <plugin interceptor="com.github.pagehelper.PageHelper"> <property name="dialect" value="mysql"/> </plugin> </plugins> 查看com.github.pagehelper安装包后发现PageI

huang_2016的博客 922

mysql四剑客_MyBatis三剑客

MyBatis三剑客MyBatis 可以通过 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。但是这个配置的过程重复度很高,开发时十分繁琐。(待学习)而MyBatis三剑客可以简化MyBatis开发的一组工具,搭配使用,可以降低开发难度,提高开发效率。三者分别为:MyBatis-generat...

weixin_42279592的博客 136
上一篇: springboot整合JSR303参数校验与全局异常处理
下一篇: 阿里P8专家,推荐学习的44个微服务架构设计模式,总共451页
Java技术那些事儿
博客等级 码龄5年 2306粉丝 2584原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址