mybatis多个plugins的执⾏顺序⼀、前⾔
在mybatis官⽹中,有插件⼀说  . 如果同时有多个插件,那么他们的执⾏顺序是怎样的?
⼆、准备⼯作、代码准备
1、 项⽬结构
2、TestDAO
public interface TestDAO {
Test selectById(Integer id);
default void testDefaultMethod(){
System.out.println("===调⽤接⼝中的默认⽅法,⽤来验证MapperProxy中的isDefaultMethod⽅法===");
}
}
3、Testpython网络爬虫能做什么
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Test {
private Integer id;
private String name;
}
4、ExamplePlugin
@Intercepts({@Signature(
type= Executor.class, method = "query", args={MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}        ),
@Signature(
type = ParameterHandler.class, method = "setParameters", args = {PreparedStatement.class}
),
@Signature(
type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}
),
@Signature(
type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}
)
})
public class ExamplePlugin implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("==== ExamplePlugin 开始搞事情:" + Method().getName() + "  ====");
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
mysql语句的执行顺序
}
}
5、SecondExamplePlugin
@Intercepts({@Signature(
type= Executor.class, method = "query", args={MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}        ),
@Signature(
type = ParameterHandler.class, method = "setParameters", args = {PreparedStatement.class}
),
while语句是先执行后判断
@Signature(
type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}
),
@Signature(
type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}
)
})
public class SecondExamplePlugin implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("==== SecondExamplePlugin 开始搞事情:" + Method().getName() + "  ====");
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
}
}
6、Main
public class Main {
public static SqlSession getSqlSession() throws IOException {
InputStream inputStream = ResourceAsStream("l");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
return sqlSessionFactory.openSession();
}
public static void main(String[] args) throws IOException {
TestDAO testDAO = getSqlSession().getMapper(TestDAO.class);
Test test = testDAO.selectById(1);
//        stDefaultMethod();
//类⽂件是缓存在java虚拟机中,我们将类⽂件打印到⽂件中,便于查看
/
/        generateProxyFile("F:/TestDAOProxy.class");
}
private static void generateProxyFile(String path){
byte[] classFile = ateProxyClass("$Proxy0", new Class<?>[]{TestDAO.class});
try(FileOutputStream fos = new FileOutputStream(path)) {
fos.write(classFile);
fos.flush();
System.out.println("代理类class⽂件写⼊成功");
} catch (Exception e) {
System.out.println("写⽂件错误");
}
}
}
7、 l
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/mybatis-3-mapper.dtd">
<mapper namespace="batis.dao.TestDAO">
<resultMap id="testMap" type="batis.domain.Test">
<result property="id" column="id" />chanelpriestonwork
<result property="name" column="name" />
</resultMap>
<sql id="allColumn">
id, name
</sql>
<select id="selectById" resultMap="testMap">
SELECT <include refid="allColumn"/>
FROM test
WHERE id = #{id}
</select>
</mapper>
8、l
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-////DTD Config 3.0//EN"
"/dtd/mybatis-3-config.dtd">
tomcat漏洞修复方法
<configuration>
<plugins>
<plugin interceptor="batis.plugin.ExamplePlugin">
<property name="someProperty" value="200" />
</plugin>
<plugin interceptor="batis.plugin.SecondExamplePlugin">
<property name="someProperty" value="200" />
</plugin>
</plugins>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="sql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJ                <property name="username" value="root"/>
<property name="password" value="NewPwd@123"/>
</dataSource>
</environment>
</environments>
补码咋转换反码
<mappers>
<mapper resource="l"/>
</mappers>
</configuration>
9、POM

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。