当前位置: 首页 > news >正文

怎么开通网站平台简历免费模板

怎么开通网站平台,简历免费模板,制作付款网站,58同城如何招聘人才我们需要想办法打印出完成的SQL,Mybatis为我们提供了 org.apache.ibatis.plugin.Interceptor接口,我们来实现该接口做一些打印SQL的工作 package org.springjmis.core.mp.plugins;import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; impor…

我们需要想办法打印出完成的SQL,Mybatis为我们提供了 org.apache.ibatis.plugin.Interceptor接口,我们来实现该接口做一些打印SQL的工作

package org.springjmis.core.mp.plugins;import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.SystemClock;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.ResultHandler;
import org.springjmis.core.tool.utils.StringUtil;import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Statement;
import java.util.*;/*** 用于输出每条 SQL 语句及其执行时间** @author hubin nieqiurong TaoYu* @since 2016-07-07*/
@Slf4j
@Intercepts({@Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),@Signature(type = StatementHandler.class, method = "update", args = Statement.class),@Signature(type = StatementHandler.class, method = "batch", args = Statement.class)
})
public class SqlLogInterceptor implements Interceptor {private static final String DRUID_POOLED_PREPARED_STATEMENT = "com.alibaba.druid.pool.DruidPooledPreparedStatement";private static final String T4C_PREPARED_STATEMENT = "oracle.jdbc.driver.T4CPreparedStatement";private static final String ORACLE_PREPARED_STATEMENT_WRAPPER = "oracle.jdbc.driver.OraclePreparedStatementWrapper";private Method oracleGetOriginalSqlMethod;private Method druidGetSqlMethod;@Overridepublic Object intercept(Invocation invocation) throws Throwable {Statement statement;Object firstArg = invocation.getArgs()[0];if (Proxy.isProxyClass(firstArg.getClass())) {statement = (Statement) SystemMetaObject.forObject(firstArg).getValue("h.statement");} else {statement = (Statement) firstArg;}MetaObject stmtMetaObj = SystemMetaObject.forObject(statement);try {statement = (Statement) stmtMetaObj.getValue("stmt.statement");} catch (Exception e) {// do nothing}if (stmtMetaObj.hasGetter("delegate")) {//Hikaritry {statement = (Statement) stmtMetaObj.getValue("delegate");} catch (Exception ignored) {}}String originalSql = null;String stmtClassName = statement.getClass().getName();if (DRUID_POOLED_PREPARED_STATEMENT.equals(stmtClassName)) {try {if (druidGetSqlMethod == null) {Class<?> clazz = Class.forName(DRUID_POOLED_PREPARED_STATEMENT);druidGetSqlMethod = clazz.getMethod("getSql");}Object stmtSql = druidGetSqlMethod.invoke(statement);if (stmtSql instanceof String) {originalSql = (String) stmtSql;}} catch (Exception e) {e.printStackTrace();}} else if (T4C_PREPARED_STATEMENT.equals(stmtClassName)|| ORACLE_PREPARED_STATEMENT_WRAPPER.equals(stmtClassName)) {try {if (oracleGetOriginalSqlMethod != null) {Object stmtSql = oracleGetOriginalSqlMethod.invoke(statement);if (stmtSql instanceof String) {originalSql = (String) stmtSql;}} else {Class<?> clazz = Class.forName(stmtClassName);oracleGetOriginalSqlMethod = getMethodRegular(clazz, "getOriginalSql");if (oracleGetOriginalSqlMethod != null) {//OraclePreparedStatementWrapper is not a public class, need set this.oracleGetOriginalSqlMethod.setAccessible(true);if (null != oracleGetOriginalSqlMethod) {Object stmtSql = oracleGetOriginalSqlMethod.invoke(statement);if (stmtSql instanceof String) {originalSql = (String) stmtSql;}}}}} catch (Exception e) {//ignore}}if (originalSql == null) {originalSql = statement.toString();}originalSql = originalSql.replaceAll("[\\s]+", StringPool.SPACE);int index = indexOfSqlStart(originalSql);if (index > 0) {originalSql = originalSql.substring(index);}// 计算执行 SQL 耗时long start = SystemClock.now();Object result = invocation.proceed();long timing = SystemClock.now() - start;// SQL 打印执行结果Object target = PluginUtils.realTarget(invocation.getTarget());MetaObject metaObject = SystemMetaObject.forObject(target);MappedStatement ms = (MappedStatement) metaObject.getValue("delegate.mappedStatement");// 打印 sqlSystem.err.println(StringUtil.format("\n==============  Sql Start  ==============" +"\nExecute ID  :{}" +"\nExecute SQL :{}" +"\nExecute Time:{} ms" +"\n==============  Sql  End   ==============\n",ms.getId(), originalSql, timing));return result;}@Overridepublic Object plugin(Object target) {if (target instanceof StatementHandler) {return Plugin.wrap(target, this);}return target;}/*** 获取此方法名的具体 Method** @param clazz      class 对象* @param methodName 方法名* @return 方法*/private Method getMethodRegular(Class<?> clazz, String methodName) {if (Object.class.equals(clazz)) {return null;}for (Method method : clazz.getDeclaredMethods()) {if (method.getName().equals(methodName)) {return method;}}return getMethodRegular(clazz.getSuperclass(), methodName);}/*** 获取sql语句开头部分** @param sql ignore* @return ignore*/private int indexOfSqlStart(String sql) {String upperCaseSql = sql.toUpperCase();Set<Integer> set = new HashSet<>();set.add(upperCaseSql.indexOf("SELECT "));set.add(upperCaseSql.indexOf("UPDATE "));set.add(upperCaseSql.indexOf("INSERT "));set.add(upperCaseSql.indexOf("DELETE "));set.remove(-1);if (CollectionUtils.isEmpty(set)) {return -1;}List<Integer> list = new ArrayList<>(set);list.sort(Comparator.naturalOrder());return list.get(0);}}

在MybatisPlusConfiguration拦截


package org.springjmis.core.boot.config;import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springjmis.core.boot.props.MybatisPlusProperties;
import org.springjmis.core.mp.plugins.SqlLogInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** mybatisplus 配置** @author Chill*/
@Configuration(proxyBeanMethods = false)
@AllArgsConstructor
@MapperScan("org.springjmis.**.mapper.**")
@EnableConfigurationProperties(MybatisPlusProperties.class)
public class MybatisPlusConfiguration {/*** mybatis-plus 拦截器集合*/@Bean@ConditionalOnMissingBean(MybatisPlusInterceptor.class)public MybatisPlusInterceptor mybatisPlusInterceptor(MybatisPlusProperties mybatisPlusProperties) {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();// 配置分页拦截器PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();paginationInnerInterceptor.setMaxLimit(mybatisPlusProperties.getPageLimit());paginationInnerInterceptor.setOverflow(mybatisPlusProperties.getOverflow());interceptor.addInnerInterceptor(paginationInnerInterceptor);return interceptor;}/*** sql 日志** @return SqlLogInterceptor*/@Bean@ConditionalOnProperty(value = "blade.mybatis-plus.sql-log", matchIfMissing = true)public SqlLogInterceptor sqlLogInterceptor() {return new SqlLogInterceptor();}}

http://www.yayakq.cn/news/508899/

相关文章:

  • 工作室 网站经营性备案网站建设大型企业
  • 句容工程建设招标网站深圳在线问诊平台
  • 公司网站首页怎么做需要做网站的公司有哪些
  • 8图片这样的网站怎么做的官网建设
  • jsp网站建设项目实战总结免费换ip软件
  • 网站开发建议白银做网站的董事
  • dede手机网站教程网站开发项目的简介
  • 北京网站制作建设wordpress启用域名邮
  • 高端交互式网站建设大型的网站开发
  • 成都游戏网站建设介绍兰州的网页
  • 无锡网站排名优化费用泉州专门做网站
  • 集团网站制作公司公司网站建设哪儿济南兴田德润实惠吗
  • 广西住房和城乡建设门户网站南阳网站排名公司
  • 肇庆百度网站推广科技前沿
  • 郴州建设局门户网站广东新闻联播今天
  • 长宁区网站建设设计如何开网店
  • 公司网站有什么作用网站域名邮箱
  • 怎么做lol网站如何引流与推广
  • iis搭建网站教程win7公司做阿里巴巴网站要多少钱
  • 石家庄网站建设团队国内做外贸网站的有哪些资料
  • 手机搭建个人网站建设田达摩托车官方网站
  • 新媒体 网站建设 影视做网站的用处
  • 洛阳市政建设网站做网站的图片分类
  • 为学校建设网站南昌网站开发模板
  • 专门做问卷调查的一个网站电视墙装修效果图2023新款
  • 做360网站优化排wordpress远程图片
  • 电子商务网站建设的方法和工具注册公司网站源码
  • 网站重新设计需要多久旅游网站建设策划书案例
  • 现代网站制作哪些网站做平面设计素材
  • 厦门网站建设公司排名电子商务网站建设类论文