mapper xml 文件学习

55 篇文章 0 订阅
<select id="countByStatus"  resultType="int">
    SELECT COUNT(distinct a.id)
         FROM task et
         inner join task_with_video b on a.id = b.task_id
     where  a.status !=2
     <if test="status != null and status != @com.myweb.enum.TaskEnum@ALL">
         and a.status = #{status}
     </if>
     <if test="@com.myweb.context.WebContextUser@contextUser() != null
             and !@com.myweb.UserRoleEnum@isSuperAdmin(@com.myweb.context.WebContextUser@contextUser().userRole)">
         <choose>
             <when test="@com.myweb.context.WebContextUser@contextUser().videos.size() > 0">
                 AND b.videoName in
                 <foreach collection="@com.myweb.context.WebContextUser@contextUser().videos"
                          index="index" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </when>
             <otherwise>
                 and 1=0
             </otherwise>
         </choose>
     </if>
 </select>
//task运行状态Enum
package com.myweb.enum;
public enum TaskStatusEnum {
	All(0),
	...
	int type;
}

//用户上下文
package com.myweb.context;
public class TaskStatusEnum {
	public static ContextUser contextUser(){}
}

分析

<select id="调用mapper.xml的方法名"  resultType="返回类型">
    SELECT COUNT(distinct a.id)
         FROM task et
         inner join task_with_video b on a.id = b.task_id
     where  a.status !=2
     <if test="status != null and status != @com.myweb.enum.TaskEnum@ALL">    //!!!枚举类型@枚举类型的一个value
         and a.status = #{status}
     </if>
     <if test="@com.myweb.context.WebContextUser@contextUser() != null  //!!!WebContextUser类@WebContextUser类中的contextUser()方法返回值 !=null 
             and !@com.myweb.UserRoleEnum@isSuperAdmin(@com.myweb.context.WebContextUser@contextUser().userRole)">       //!!!!UserRoleEnum类@类的isSuperAdmin()方法,参数为 WebContextUser@contextUser() 返回值的 userRole属性
         <choose>
         	//!!!!WebContextUser@contextUser()方法返回值的videos属性的size()方法 返回值>0
             <when test="@com.myweb.context.WebContextUser@contextUser().videos.size() > 0">
                 AND b.videoName in
                 <foreach collection="@com.myweb.context.WebContextUser@contextUser().videos"
                          index="index" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </when>
             <otherwise>      //!!!! when 不成立的时候 进入 otherwise
                 and 1=0
             </otherwise>
         </choose>
     </if>
 </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值