mybatis的复习题总结

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用到的设计模式

日志模块:代理模式、适配器模式

数据源模块:代理模式、工厂模式

缓存模块:装饰器模式

初始化阶段:建造者模式

代理阶段:策略模式

数据读写阶段:模板模式

插件化开发:责任链模式

4.mybatis的优缺点

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值