1.#{}和${}的区别
$符号
SELECT
f.id as id,
f.`name` as `name`,
f.type as type,
f.father_id as fatherId,
c.id as subId,
c.`name` as subName,
c.type as subType,
c.father_id as subFatherId
FROM
category f
LEFT JOIN
category c
on
f.id = c.father_id
WHERE
f.father_id = #{rootCatId} and f.name = ${test}
</select>
在这里插入代码片
$在executor生成boundsql的时候会直接替换拼接sql
2.#号
SELECT
f.id as id,
f.`name` as `name`,
f.type as type,
f.father_id as fatherId,
c.id as subId,
c.`name` as subName,
c.type as subType,
c.father_id as subFatherId
FROM
category f
LEFT JOIN
category c
on
f.id = c.father_id
WHERE
f.father_id = #{rootCatId} and f.name = #{test}
#号里面的值在生成boundsql会生成?来预编译。
2.解释下mybatis面向接口编程
接口的使命是生成代理类,并根据代理类的全路径和方法生成id在MapperRegisty找到MappedStatement.
首先在sqlSession中的configuration有个MapperRegisty。里面有个knowMappers,里面的key是接口Class类,值是接口生成的代理类。
这个代理类掉对应方法时,首先生成MappedMethod,里面有类的全路径和方法生成id,根据这个id在configuration中找到MapperdStateMent.
3.mybatis用到的设计模式
日志模块:代理模式、适配器模式
数据源模块:代理模式、工厂模式
缓存模块:装饰器模式
初始化阶段:建造者模式
代理阶段:策略模式
数据读写阶段:模板模式
插件化开发:责任链模式