mybatis (zj_id LIKE '1|2|2%' OR zj_id LIKE '1|3|2%')查询条件怎么在xml文件中写?
(zj_idLIKE'1|2|2%'ORzj_idLIKE'1|3|2%')一个字段的查询,但是查询内容不一样,该如何在mybatis.xml文件中写呢?mysql语句如...
(zj_id LIKE '1|2|2%' OR zj_id LIKE '1|3|2%') 一个字段的查询,但是查询内容不一样,该如何在mybatis.xml文件中写呢?
mysql 语句如下:
SELECT qu_id FROM admin_point_relation
WHERE
(zj_id LIKE '1|2|2%' OR zj_id LIKE '1|3|2%')
AND qu_type = 11
AND is_mark = 1
AND use_count < 20
mybatis mapper.xml 文件中:
<select id="getQuestionIdsByParam" resultType="PRM" parameterType="PRM">
SELECT qu_id FROM admin_point_relation
<where>
<if test="qu_id!=null && qu_id > 0">
qu_id=#{qu_id}
</if>
<if test="qu_type!=null && qu_type > 0">
and qu_type = #{qu_type}
</if>
<if test="zy_id !=null && zy_id > 0">
and zy_id = #{zy_id}
</if>
<if test="is_mark != null && is_mark > 0">
and is_mark = #{is_mark}
</if>
<if test="use_count != null && use_count > 0">
and use_count $lt; #{is_mark}
</if>
</where>
</select> 展开
mysql 语句如下:
SELECT qu_id FROM admin_point_relation
WHERE
(zj_id LIKE '1|2|2%' OR zj_id LIKE '1|3|2%')
AND qu_type = 11
AND is_mark = 1
AND use_count < 20
mybatis mapper.xml 文件中:
<select id="getQuestionIdsByParam" resultType="PRM" parameterType="PRM">
SELECT qu_id FROM admin_point_relation
<where>
<if test="qu_id!=null && qu_id > 0">
qu_id=#{qu_id}
</if>
<if test="qu_type!=null && qu_type > 0">
and qu_type = #{qu_type}
</if>
<if test="zy_id !=null && zy_id > 0">
and zy_id = #{zy_id}
</if>
<if test="is_mark != null && is_mark > 0">
and is_mark = #{is_mark}
</if>
<if test="use_count != null && use_count > 0">
and use_count $lt; #{is_mark}
</if>
</where>
</select> 展开
1个回答
展开全部
传入两个zj_id1和zj_id2进来:
<if test="null!=zj_id1 and null!=zj_id2">
and (zj_id like #{zj_id1} or zj_id like #{zj_id2})
</test>
<if test="null!=zj_id1 and null==zj_id2">
and zj_id like #{zj_id1}
</test>
<if test="null==zj_id1 and null!=zj_id2">
and zj_id like #{zj_id2}
</test>
<if test="null!=zj_id1 and null!=zj_id2">
and (zj_id like #{zj_id1} or zj_id like #{zj_id2})
</test>
<if test="null!=zj_id1 and null==zj_id2">
and zj_id like #{zj_id1}
</test>
<if test="null==zj_id1 and null!=zj_id2">
and zj_id like #{zj_id2}
</test>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询