介绍
这期内容当中小编将会给大家带来有关怎么在SpringBoot中利用MybatisSQL对@Intercepts进行过滤,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
<强>开发环境:强>
<强>弹簧引导+ mybatis 强>
@ component @Intercepts ({, @Signature (type =, Executor.class,, method =,“query",, args =, {Object.class, MappedStatement.class,还以为,RowBounds.class, ResultHandler.class }),}) public class  SqlInterceptor implements Interceptor  { private 才能Logger Logger =, LoggerFactory.getLogger (SqlInterceptor.class); @Override才能 public 才能;Object 拦截(Invocation 调用),throws Throwable { ,logger.info(“拦截……“);//,,,,获取sql ,MappedStatement MappedStatement =, (MappedStatement), invocation.getArgs () [0]; ,Object parameter =, invocation.getArgs () [1]; ,BoundSql BoundSql =, mappedStatement.getBoundSql(参数); ,String oldsql =, boundSql.getSql (); ,logger.info(“老:“+ oldsql);//,,,,判断sql是否有哪条件。改变sql。 ,boolean status =, oldsql.toLowerCase () .contains (“where"); ,if (地位),{ ,,BoundSql newBoundSql =, new BoundSql (mappedStatement.getConfiguration (),, oldsql +,“,以及1=1“, ,,,,,,boundSql.getParameterMappings (),, boundSql.getParameterObject ()); ,,MappedStatement newMs =, copyFromMappedStatement (mappedStatement, new BoundSqlSqlSource (newBoundSql)); ,,invocation.getArgs () [0],=, newMs; ,}//,继续执行 ,Object result =, invocation.proceed (); ,return 结果; ,,} @Override才能 public 才能;Object 插件(Object 目标),{ ,return Plugin.wrap(目标,,); ,,} @Override才能 public 才能;void 找(Properties 属性),{ ,,}//,才能复制原始MappedStatement private 才能;MappedStatement  copyFromMappedStatement (MappedStatement 女士,SqlSource newSqlSource), { ,MappedStatement.Builder builder =, new MappedStatement.Builder (ms.getConfiguration (),, ms.getId (),, newSqlSource, ,,,,ms.getSqlCommandType ()); ,builder.resource (ms.getResource ()); ,builder.fetchSize (ms.getFetchSize ()); ,builder.statementType (ms.getStatementType ()); ,builder.keyGenerator (ms.getKeyGenerator ()); ,if (ms.getKeyProperties (), !=, null), { ,,for (String keyProperty : ms.getKeyProperties ()), { ,,,,builder.keyProperty (keyProperty); ,,} ,} ,builder.timeout (ms.getTimeout ()); ,builder.parameterMap (ms.getParameterMap ()); ,builder.resultMaps (ms.getResultMaps ()); ,builder.cache (ms.getCache ()); ,builder.useCache (ms.isUseCache ()); ,return builder.build (); ,,} public 才能static class  BoundSqlSqlSource implements SqlSource { ,BoundSql boundSql; ,public BoundSqlSqlSource (BoundSql boundSql), { ,,this.boundSql =, boundSql; ,} ,public BoundSql  getBoundSql (Object parameterObject), { ,,return boundSql; ,} ,,} }
上述就是小编为大家分享的怎么在SpringBoot中利用MybatisSQL对@Intercepts进行过滤了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。