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

阅读 82

2022-04-06

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)

0 0 举报