mybatis相关函数

MyBatis中的if....else...表示方法

<choose>
    <when test="">
        //...
    </when>
    <otherwise>
        //...
    </otherwise>
</choose>

其中choose为一个整体 
when是if 
otherwise是else

示例:

<select id="selectSelective" resultMap="xxx" parameterType="xxx">
    select
    <include refid="Base_Column_List"/>
    from xxx
    where del_flag=0
    <choose>
        <when test="xxx !=null and xxx != ''">
            and xxx like concat(concat('%', #{xxx}), '%')
        </when>
        <otherwise>
            and xxx like '**%'
        </otherwise>
    </choose>
</select>

 

MyBatis中的 case when 表示方法

CASE WHEN condition THEN result
 
[WHEN...THEN...]
 
ELSE result
 
END


condition是一个返回布尔类型的表达式,如果表达式返回true,则整个函数返回相应result的值,如果表达式皆为false,则返回ElSE后result的值,如果省略了ELSE子句,则返回NULL。

 

示例:

SELECT
    STUDENT_NAME,
  (CASE WHEN score < 60 THEN '不及格'
        WHEN score >= 60 AND score < 80 THEN '及格'
        WHEN score >= 80 THEN '优秀'
        ELSE '异常' END) AS REMARK
FROM TABLE

  

posted @ 2020-04-23 11:42  tomingto  阅读(1150)  评论(0编辑  收藏  举报