mybatis

作者: 百炼 | 来源:发表于2018-07-27 22:26 被阅读0次

    mybatis test使用字符串,而不是使用自带的强转

    说明

    1. 使用test="delReason != '' and delReason != null"默认是String
    2. 使用test = "delReason != 1 and delReason != 0" 默认是Integer

    场景说明
    开发一项目,统一删除的原因(两个字节),第一个字节是大的类别(如1手动删除,2系统删除)第二个字节是小的类别(如手动删除下包括:11与企业经营无关,12 带有侮辱词汇。系统删除下包括:21 系统删除原因1,22系统删除2 )

    查询手动删除的(包括11,12两类)
    查询手动删除下的与企业无关(11类)

    java方法

    List<Student> selectStudentInfo(@Param("delReason") String delReason);
    
        <select id="selectStudentInfo" resultMap="BaseResultMap">
            SELECT id, delreason, username, salary, birthday
            FROM STUDENT
            <where>
                <choose>
                    <when test='delReason == "" or delReason == null or delReason == "-1"'>
                    </when>
                    <when test='delReason == "1"'>
                        AND LEFT(delreason,1) = #{delReason}
                    </when>
                    <when test='delReason == "2"'>
                        AND LEFT(delreason,1) = #{delReason}
                    </when>
                    <otherwise>
                        AND delreason = #{delReason}
                    </otherwise>
                </choose>
            </where>
        </select>
    

    相关文章

      网友评论

        本文标题:mybatis

        本文链接:https://www.haomeiwen.com/subject/nlhnmftx.html