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

网站的ftp怎么登陆店铺推广方法

网站的ftp怎么登陆,店铺推广方法,国内html5视频网站建设,带产品展示的个人网站模板Mybatis为我们提供了拦截器机制用于插件的开发,使用拦截器可以无侵入的开发Mybatis插件,Mybatis允许我们在SQL执行的过程中进行拦截,提供了以下可供拦截的接口: Executor:执行器ParameterHandler:参数处理…

Mybatis为我们提供了拦截器机制用于插件的开发,使用拦截器可以无侵入的开发Mybatis插件,Mybatis允许我们在SQL执行的过程中进行拦截,提供了以下可供拦截的接口:

  1. Executor:执行器
  2. ParameterHandler:参数处理器
  3. StatementHandler:语句处理器
  4. ResultSetHandler:结果集处理器

本篇我们使用拦截器统计查询语句的执行时间:

一、执行时间拦截器

在cn.horse.demo下创建QueryExecuteTimeInterceptor类

QueryExecuteTimeInterceptor类:

package cn.horse.demo;import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;import java.util.Properties;@Intercepts({@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class }),@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class })
})
public class QueryExecuteTimeInterceptor implements Interceptor {private static final Log LOG = LogFactory.getLog(QueryExecuteTimeInterceptor.class);@Overridepublic Object intercept(Invocation invocation) throws Throwable {long startTime = System.currentTimeMillis();Object result = invocation.proceed();long endTime = System.currentTimeMillis();LOG.debug("执行时间: " + (endTime - startTime) + "ms");return result;}@Overridepublic Object plugin(Object target) {return Plugin.wrap(target, this);}@Overridepublic void setProperties(Properties properties) {}
}

@Intercepts配置拦截器用于拦截的哪些接口中的哪些方法。

@Signature配置拦截器用于拦截的哪个接口中的哪个方法,需要提供接口类型,方法名,方法参数。

这里我们拦截了Executor接口中的query方法,此方法是用于执行查询的方法;在实现中,Invocation对象包含了接口(被拦截的接口Executor)、方法(被拦截的方法query)、方法参数等信息,调用proceed方法用于执行被拦截的方法(这里被拦截的方法是Executor的query方法),我们在方法执行前和方法之后进行计时计算出查询的执行时间。

二、配置拦截器

在resources下新建mybatis-config.xml配置文件,并引入QueryExecuteTimeInterceptor拦截器

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><settings><setting name="logImpl" value="JDK_LOGGING"/></settings><plugins><plugin interceptor="cn.horse.demo.QueryExecuteTimeInterceptor" /></plugins><environments default="development"><environment id="development"><transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="org.gjt.mm.mysql.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&amp;useSSL=false&amp;characterEncoding=utf8&amp;allowMultiQueries=true"/><property name="username" value="root"/><property name="password" value="horse"/></dataSource></environment></environments>
</configuration>

这里使用plugin标签在mybatis-config.xml配置文件中配置拦截器

三、启动程序

1、数据准备

这里我们直接使用脚本初始化数据库中的数据

-- 如果数据库不存在则创建数据库
CREATE DATABASE IF NOT EXISTS demo DEFAULT CHARSET utf8;
-- 切换数据库
USE demo;
-- 创建用户表
CREATE TABLE IF NOT EXISTS T_USER(ID INT PRIMARY KEY,USERNAME VARCHAR(32) NOT NULL,AGE INT NOT NULL 
);
-- 插入用户数据
INSERT INTO T_USER(ID, USERNAME, AGE)
VALUES(1, '张三', 20),(2, '李四', 22),(3, '王五', 24);

创建了一个名称为demo的数据库;并在库里创建了名称为T_USER的用户表并向表中插入了数据

2、创建实体类

在cn.horse.demo下创建UserInfo类

UserInfo类:

package cn.horse.demo;public class UserInfo {private Integer id;private String name;private Integer age;public void setId(Integer id) {this.id = id;}public Integer getId() {return id;}public void setName(String name) {this.name = name;}public String getName() {return name;}public void setAge(Integer age) {this.age = age;}public Integer getAge() {return age;}@Overridepublic String toString() {StringBuilder stringBuilder = new StringBuilder();stringBuilder.append('{');stringBuilder.append("id: " + this.id);stringBuilder.append(", ");stringBuilder.append("name: " + this.name);stringBuilder.append(", ");stringBuilder.append("age: " + this.age);stringBuilder.append('}');return stringBuilder.toString();}
}

3、创建映射器、Mapper配置

在cn.horse.demo下创建UserInfoMapper接口

UserInfoMapper接口:

package cn.horse.demo;import java.util.List;public interface UserInfoMapper {List<UserInfo> find();
}

在resources下创建cn/horse/demo目录,并在此目录下创建UserInfoMapper.xml配置文件

UserInfoMapper.xml配置:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.horse.demo.UserInfoMapper"><resultMap id="userInfoMap" type="cn.horse.demo.UserInfo"><result column="ID" property="id" /><result column="USERNAME" property="name"/><result column="AGE" property="age"/></resultMap><select id="find" resultMap="userInfoMap">SELECTID,USERNAME,AGEFROM T_USER</select>
</mapper>

4、引入配置文件

在resources下mybatis-config.xml配置文件中引入UserInfoMapper映射器。

<mappers><mapper class="cn.horse.demo.UserInfoMapper" />
</mappers>

这里我们使用mapper引入映射器,只需要设置class属性为UserInfoMapper接口的全限类名。

5、会话工具类

在cn.horse.demo包下新建SqlSessionUtils工具类

package cn.horse.demo;import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.InputStream;
import java.util.Objects;public class SqlSessionUtils {private static final SqlSessionFactory sqlSessionFactory;static {// 读取mybatis配置文件InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("mybatis-config.xml");// 根据配置创建SqlSession工厂sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);}/*** 开启会话* @return*/public static SqlSession openSession() {return sqlSessionFactory.openSession();}/*** 关闭会话* @param sqlSession*/public static void closeSession(SqlSession sqlSession) {if(Objects.nonNull(sqlSession)) {sqlSession.close();}}
}

6、JDK 日志系统配置

在resources的目录下新建logging.properties配置文件

handlers=java.util.logging.ConsoleHandler
.level=INFOcn.horse.demo.UserInfoMapper.level=FINER
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tT.%1$tL %4$s %3$s - %5$s%6$s%n

在cn.horse.demo下创建JdkLogConfig类

JdkLogConfig类:

package cn.horse.demo;import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;public class JdkLogConfig {public JdkLogConfig() {try {InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("logging.properties");LogManager.getLogManager().readConfiguration(inputStream);} catch (IOException e) {throw new RuntimeException(e);}}
}

7、启动程序

package cn.horse.demo;import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;import java.util.List;
import java.util.function.Consumer;public class Main {private static final Log LOG;static {// 引入JDK日志配置System.setProperty("java.util.logging.config.class", "cn.horse.demo.JdkLogConfig");LOG = LogFactory.getLog("cn.horse.demo.Main");}public static void main(String[] args) {// 查询find();}private static void find() {execute((UserInfoMapper userInfoMapper) -> {List<UserInfo> userInfoList = userInfoMapper.find();for (UserInfo userInfo: userInfoList) {LOG.debug(userInfo.toString());}});}private static void execute(Consumer<UserInfoMapper> function) {SqlSession sqlSession = null;try {sqlSession = SqlSessionUtils.openSession();function.accept(sqlSession.getMapper(UserInfoMapper.class));sqlSession.commit();} finally {SqlSessionUtils.closeSession(sqlSession);}}
}

execute方法用于执行操作,方法中使用sqlSession.getMapper方法获取映射器对象,然后将映射器对象具体的执行操作委托给了Consumer对象。

执行的结果如下:


文章转载自:
http://moorcroft.tgcw.cn
http://demobilize.tgcw.cn
http://glassblower.tgcw.cn
http://unanswered.tgcw.cn
http://orchotomy.tgcw.cn
http://spurwort.tgcw.cn
http://blabbermouth.tgcw.cn
http://brakesman.tgcw.cn
http://conglobate.tgcw.cn
http://buntons.tgcw.cn
http://wardroom.tgcw.cn
http://macchinetta.tgcw.cn
http://tartan.tgcw.cn
http://fontanelle.tgcw.cn
http://telos.tgcw.cn
http://tungusian.tgcw.cn
http://concert.tgcw.cn
http://smasher.tgcw.cn
http://philogynist.tgcw.cn
http://reg.tgcw.cn
http://seaquake.tgcw.cn
http://thermonuke.tgcw.cn
http://spermatogenic.tgcw.cn
http://stokehold.tgcw.cn
http://selfishness.tgcw.cn
http://gimp.tgcw.cn
http://brick.tgcw.cn
http://comprador.tgcw.cn
http://intermezzi.tgcw.cn
http://disfrock.tgcw.cn
http://verminosis.tgcw.cn
http://impulsive.tgcw.cn
http://poddock.tgcw.cn
http://whorled.tgcw.cn
http://rotational.tgcw.cn
http://optative.tgcw.cn
http://planography.tgcw.cn
http://nighttime.tgcw.cn
http://institutionalise.tgcw.cn
http://unlay.tgcw.cn
http://factionalism.tgcw.cn
http://megacephalous.tgcw.cn
http://expurgatorial.tgcw.cn
http://mitigation.tgcw.cn
http://gaborone.tgcw.cn
http://temerarious.tgcw.cn
http://capriccioso.tgcw.cn
http://union.tgcw.cn
http://surefire.tgcw.cn
http://unchecked.tgcw.cn
http://endogenous.tgcw.cn
http://ccitt.tgcw.cn
http://willies.tgcw.cn
http://thickback.tgcw.cn
http://insuperable.tgcw.cn
http://sandy.tgcw.cn
http://locomotory.tgcw.cn
http://tickbird.tgcw.cn
http://antitoxin.tgcw.cn
http://ovulary.tgcw.cn
http://nii.tgcw.cn
http://cyclo.tgcw.cn
http://thermionics.tgcw.cn
http://pioupiou.tgcw.cn
http://empanada.tgcw.cn
http://signatureless.tgcw.cn
http://yegg.tgcw.cn
http://fentanyl.tgcw.cn
http://episcopalism.tgcw.cn
http://eschatological.tgcw.cn
http://ironwork.tgcw.cn
http://platysma.tgcw.cn
http://slipup.tgcw.cn
http://polyphyleticism.tgcw.cn
http://oxidimetry.tgcw.cn
http://chemiosmotic.tgcw.cn
http://eyewater.tgcw.cn
http://bacteriologist.tgcw.cn
http://atween.tgcw.cn
http://cantaloupe.tgcw.cn
http://thyrotoxic.tgcw.cn
http://nudibranch.tgcw.cn
http://promotional.tgcw.cn
http://mechanician.tgcw.cn
http://fatal.tgcw.cn
http://demonolatry.tgcw.cn
http://supersensitize.tgcw.cn
http://superchurch.tgcw.cn
http://comfrey.tgcw.cn
http://gammadia.tgcw.cn
http://reedman.tgcw.cn
http://limb.tgcw.cn
http://disdainful.tgcw.cn
http://corpsman.tgcw.cn
http://correlated.tgcw.cn
http://wanderingly.tgcw.cn
http://heartily.tgcw.cn
http://subjugate.tgcw.cn
http://ausgleich.tgcw.cn
http://cellulate.tgcw.cn
http://www.dt0577.cn/news/122608.html

相关文章:

  • 我要建个网站在线客服
  • 网站制作理念公众号营销
  • 网站最上面标题怎么改网站排名优化+o+m
  • 做金融网站需要什么营业执照谷歌搜索引擎下载
  • 电商网站营销方案影视网站怎么优化关键词排名
  • 专门做课件的网站北海百度seo
  • 整形医院网站制作最新新闻热点事件
  • 网站隐藏的案例怎么看搜索引擎营销的五大特点
  • wordpress建政府网站全球网站排行榜
  • 东网站建设网页链接
  • 网站建设绪论肇庆seo优化
  • 网站建设策划 优帮云广州网站优化页面
  • 智慧园区建设规划方案seo关键词优化排名推广
  • 丽水市做网站的广州网站seo地址
  • 温州做网站的公司优化营商环境工作总结
  • 服务器 网站 appapp推广实名认证接单平台
  • 内部网站建设产品推广词
  • 乌鲁木齐新市区建设局网站营销策划
  • 用网站做宣传的费用网络营销专业是干嘛的
  • 网站代码免费的如何学会推广和营销
  • 只用网站开发VS就安装那些就够了智能网站排名优化
  • 18网站推广如何申请网站域名流程
  • 阿里云建网站我想做百度推广
  • 商城网站建设代理商专业外贸网络推广
  • 建设网站考虑因素电商网站分析
  • 个人备案的网站销售商品seo和点击付费的区别
  • 广西住房与城乡建设部网站苏州seo优化公司
  • 网站推广做招商加盟深圳百度推广排名优化
  • 做网站的时候表格怎么去掉专门开发小程序的公司
  • 网站开发建设需要多少钱徐州百度seo排名优化