mybatis test使用字符串,而不是使用自带的强转
说明
- 使用
test="delReason != '' and delReason != null"
默认是String
- 使用
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>
网友评论