mybatis源码分析(四):SqlNode

SqlNode

SqlNode代表我们写的动态sql里的每个节点,那么什么叫动态sql呢?动态sql就是会根据我们的入参,来动态生成最终的sql,比如下面这个例子

<select id="findPost" resultType="org.apache.ibatis.domain.blog.Post">
   SELECT *
   FROM POST P
   <where>
     <choose>
       <when test="id != null">id = #{id}</when>
       <when test="author_id != null">AND author_id = #{author_id}</when>
       <otherwise>
         <if test="ids != null">
           AND id IN
           <foreach item="item_id" index="index" open="(" close=")" separator="," collection="ids">#{ids[${index}]}
           </foreach>
         </if>
         <trim prefix="AND">
           <include refid="byBlogId">
               <property name="prefix" value="blog"/>
           </include>
         </trim>
       </otherwise>
     </choose>
   </where>
 </select>

DynamicContext

在介绍SqlNode之前,首先介绍下SqlNode中常用的DynamicContext
DynamicContext从名字可以看出,它使动态sql解析过程中的上下文,其主要作用有两个:

  1. 将动态sql解析之后的sql片段保存下来
  2. 持有解析过程中使用到的参数
public class DynamicContext {
   

  public static final String PARAMETER_OBJECT_KEY = "_parameter";
  public static final String DATABASE_ID_KEY = "_databaseId";

  static {
   
    // 设置当通过ognl来访问ContextMap类型的对象时,使用ContextAccessor来进行方法
    // 使用Cont
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值