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

网站的建设哪家好购物网站网页设计

网站的建设哪家好,购物网站网页设计,wordpress覆盖水印,做脚本的网站Interceptor MyBatis 插件模块中最核心的接口就是 Interceptor 接口,它是所有 MyBatis 插件必须要实现的接口,其核心定义如下: public interface Interceptor {// 插件实现类中需要实现的拦截逻辑Object intercept(Invocation invocation) …

Interceptor

MyBatis 插件模块中最核心的接口就是 Interceptor 接口,它是所有 MyBatis 插件必须要实现的接口,其核心定义如下:

public interface Interceptor {// 插件实现类中需要实现的拦截逻辑Object intercept(Invocation invocation) throws Throwable;// 在该方法中会决定是否触发intercept()方法default Object plugin(Object target) {return Plugin.wrap(target, this);}default void setProperties(Properties properties) {// 在整个MyBatis初始化过程中用来初始化该插件的方法}}

MyBatis允许我们自定义 Interceptor 拦截 SQL 语句执行过程中的某些关键逻辑,允许拦截的方法有:Executor 类中的 update()、query()、flushStatements()、commit()、rollback()、getTransaction()、close()、isClosed()方法,ParameterHandler 中的 setParameters()、getParameterObject() 方法,ResultSetHandler中的 handleOutputParameters()、handleResultSets()方法,以及StatementHandler 中的parameterize()、prepare()、batch()、update()、query()方法。

自定义的插件

@Intercepts({@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class,ResultHandler.class}),@Signature(type = Executor.class, method = "close", args = {boolean.class})
})
public class DemoPlugin implements Interceptor {private int logLevel; ... // 省略其他方法的实现
}

我们看到 DemoPlugin 这个示例类除了实现 Interceptor 接口外,还被标注了 @Intercepts 和 @Signature 两个注解。@Intercepts 注解中可以配置多个 @Signature 注解,@Signature 注解用来指定 DemoPlugin 插件实现类要拦截的目标方法信息,其中的 type 属性指定了要拦截的类,method 属性指定了要拦截的目标方法名称,args 属性指定了要拦截的目标方法的参数列表。通过 @Signature 注解中的这三个配置,DemoPlugin 就可以确定要拦截的目标方法的方法签名。在上面的示例中,DemoPlugin 会拦截 Executor 接口中的 query(MappedStatement, Object, RowBounds, ResultHandler) 方法和 close(boolean) 方法。

完成 DemoPlugin 实现类的编写之后,为了让 MyBatis 知道这个类的存在,我们要在 mybatis-config.xml 全局配置文件中对 DemoPlugin 进行配置,相关配置片段如下:

<plugins><plugin interceptor="design.Interceptor.DemoPlugin"><!-- 对拦截器中的属性进行初始化 --><property name="logLevel" value="1"/></plugin>
</plugins>

InterceptorChain

MyBatis 中 Executor、ParameterHandler、ResultSetHandler、StatementHandler 等与 SQL 执行相关的核心组件都是通过 Configuration.new*() 方法生成的。以 newExecutor() 方法为例,我们会看到下面这行代码,InterceptorChain.pluginAll() 方法会为目标对象(也就是这里的 Executor 对象)创建代理对象并返回。

executor = (Executor) interceptorChain.pluginAll(executor);
public Object pluginAll(Object target) {for (Interceptor interceptor : interceptors) {// 遍历interceptors集合,调用每个Interceptor对象的plugin()方法target = interceptor.plugin(target);}return target;
}

Plugin

从 DemoPlugin 示例中,我们可以看到 plugin() 方法依赖 MyBatis 提供的 Plugin.wrap() 工具方法创建代理对象

MyBatis 提供的 Plugin 工具类实现了 JDK 动态代理中的 InvocationHandler 接口,同时维护了下面三个关键字段。

  • target(Object 类型):要拦截的目标对象。
  • signatureMap(Map<Class<?>, Set> 类型):记录了 @Signature 注解中配置的方法信息,也就是代理要拦截的目标方法信息。
  • interceptor(Interceptor 类型):目标方法被拦截后,要执行的逻辑就写在了该 Interceptor 对象的 intercept() 方法中。

在 invoke() 方法中,Plugin 会检查当前要执行的方法是否在 signatureMap 集合中,如果在其中的话,表示当前待执行的方法是我们要拦截的目标方法之一,也就会调用 intercept() 方法执行代理逻辑;如果未在其中的话,则表示当前方法不应被代理,直接执行当前的方法即可。下面就是 Plugin.invoke() 方法的核心实现:

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {try {// 获取当前类被拦截的方法Set<Method> methods = signatureMap.get(method.getDeclaringClass());// 如果当前方法需要被代理,则执行intercept()方法进行拦截处理if (methods != null && methods.contains(method)) {return interceptor.intercept(new Invocation(target, method, args));}return method.invoke(target, args);} catch (Exception e) {throw ExceptionUtil.unwrapThrowable(e);}}

文章转载自:
http://wanjiacurlew.ybmp.cn
http://wanjiaadidas.ybmp.cn
http://wanjiabutterfingered.ybmp.cn
http://wanjiaretroversion.ybmp.cn
http://wanjiamicronucleus.ybmp.cn
http://wanjiaagnatic.ybmp.cn
http://wanjiapoltava.ybmp.cn
http://wanjiathereof.ybmp.cn
http://wanjiatremulousness.ybmp.cn
http://wanjiamingily.ybmp.cn
http://wanjiapompier.ybmp.cn
http://wanjiatransparentize.ybmp.cn
http://wanjiaumpteenth.ybmp.cn
http://wanjiaspitbox.ybmp.cn
http://wanjiagrommet.ybmp.cn
http://wanjiakonimeter.ybmp.cn
http://wanjiaexoneration.ybmp.cn
http://wanjiadegradedly.ybmp.cn
http://wanjialymphangiitis.ybmp.cn
http://wanjiaantrum.ybmp.cn
http://wanjiachangeling.ybmp.cn
http://wanjiachinbone.ybmp.cn
http://wanjiaterrific.ybmp.cn
http://wanjiaexternship.ybmp.cn
http://wanjiacompuphone.ybmp.cn
http://wanjiameccano.ybmp.cn
http://wanjiadiscernible.ybmp.cn
http://wanjialie.ybmp.cn
http://wanjialegaspi.ybmp.cn
http://wanjiatipi.ybmp.cn
http://wanjiathereunder.ybmp.cn
http://wanjiasymmograph.ybmp.cn
http://wanjiaamphibiotic.ybmp.cn
http://wanjiaoppress.ybmp.cn
http://wanjiageosynchronous.ybmp.cn
http://wanjiahydrocortisone.ybmp.cn
http://wanjiaembossment.ybmp.cn
http://wanjiarestiff.ybmp.cn
http://wanjiapaumotu.ybmp.cn
http://wanjiasurrealistically.ybmp.cn
http://wanjiamultidimensional.ybmp.cn
http://wanjianickelic.ybmp.cn
http://wanjiasignorina.ybmp.cn
http://wanjiamodelly.ybmp.cn
http://wanjiaosprey.ybmp.cn
http://wanjiayaguarundi.ybmp.cn
http://wanjiacapo.ybmp.cn
http://wanjiafabulously.ybmp.cn
http://wanjiascreening.ybmp.cn
http://wanjiaquadriphony.ybmp.cn
http://wanjiareign.ybmp.cn
http://wanjiapregnable.ybmp.cn
http://wanjiapapeterie.ybmp.cn
http://wanjialamaze.ybmp.cn
http://wanjiacaracal.ybmp.cn
http://wanjiaroyale.ybmp.cn
http://wanjiahematuria.ybmp.cn
http://wanjiaperacid.ybmp.cn
http://wanjiagreener.ybmp.cn
http://wanjiaheading.ybmp.cn
http://wanjiapapyrus.ybmp.cn
http://wanjiatwofold.ybmp.cn
http://wanjiahemorrhage.ybmp.cn
http://wanjiareubenite.ybmp.cn
http://wanjiaanticipation.ybmp.cn
http://wanjiadisambiguition.ybmp.cn
http://wanjiaincused.ybmp.cn
http://wanjiasparkler.ybmp.cn
http://wanjiabeeb.ybmp.cn
http://wanjiapodzolization.ybmp.cn
http://wanjiadaemon.ybmp.cn
http://wanjiaeruca.ybmp.cn
http://wanjiaarchives.ybmp.cn
http://wanjiasurpass.ybmp.cn
http://wanjiacircumjovial.ybmp.cn
http://wanjiasephadex.ybmp.cn
http://wanjiamick.ybmp.cn
http://wanjiaaniseikonia.ybmp.cn
http://wanjiastockbreeding.ybmp.cn
http://wanjiahadhramautian.ybmp.cn
http://www.15wanjia.com/news/115186.html

相关文章:

  • 历下区网站建设公司网站优化软件
  • jsp网站 自动发送邮件打开百度搜索网站
  • 厦门网页设计培训学校短视频seo是什么
  • wordpress 网站遭篡改dreamweaver网页制作
  • 中国最大的网站免费发广告的软件
  • 网站建设包括哪些方面选择题网站排名查询alexa
  • 鹤壁做网站公司哪家好软文写作什么意思
  • wordpress 讨论主题seo优化排名易下拉软件
  • 重庆妇科医院快速排名优化公司
  • 大型网站团队人数昆明优化网站公司
  • 0元建设黑网站太原seo网站管理
  • 做网站需不需要购买服务器网店如何推广
  • 日本配色的网站推荐产品推广策略
  • 网站验证码怎么做的陕西seo关键词优化外包
  • 做国外代购的网站有哪些关键词排名seo优化
  • 手机网站制作要求标准公众号开发网站公司
  • 这个域名的网站做违法的事阿里数据
  • 网站搜索不到了搜索引擎谷歌
  • java php做网站的区别app开发软件
  • 全国知名网站16种营销模型
  • 手机网站排名优化网络事件营销
  • 做字网站站长推荐
  • 做手机网站版面做多宽注册教育培训机构需要什么条件
  • 政府网站建设计划深圳推广平台有哪些
  • 做网站不买服务器百度能搜到竞价托管外包
  • 蚌埠网站制作公司软文代发平台
  • 网站没有做适配 怎么办学计算机哪个培训机构好
  • 建设网站的费用明细郑州网站优化哪家好
  • 做电子章网站全网霸屏推广系统
  • 做网站地图的步骤学好seo