0
点赞
收藏
分享

微信扫一扫

Mybatis 的if判断里面的 test使用length()判断字符串长度

慕容冲_a4b8 2022-04-06 阅读 82
java后端

Mybatis 的if判断里面的 test使用length()判断字符串长度

在Mybatis里面需要根据字符串的长度判断取不同的字段或者获取字段的长度。

<choose>
    <when test="categoryIds != null and categoryIds != '' and categoryIds.length() == 3">
        AND SUBSTR(moi.category_id, 1, 3) = #{categoryIds}
    </when>
    <when test="categoryIds != null and categoryIds != '' and categoryIds.length() == 6">
        AND SUBSTR(moi.category_id, 1, 6) = #{categoryIds}
    </when>
    <when test="categoryIds != null and categoryIds != '' and categoryIds.length() == 9">
        AND SUBSTR(moi.category_id, 1, 9) = #{categoryIds}
    </when>
    <otherwise></otherwise>
</choose>
举报

相关推荐

0 条评论