mybatis where标签用法
Mybatis的
1.用法一:在动态SQL中使用
示例代码:
<select id="selectUsers" parameterType="map" resultType="User">
SELECT * FROM user
<where>
<if test="name != null">
AND name = #{name}
</if>
<if test="age != null">
AND age = #{age}
</if>
<if test="email != null">
AND email = #{email}
</if>
</where>
</select>
2.用法二:在动态SQL中使用
示例代码:
<select id="selectUsers" parameterType="map" resultType="User">
SELECT * FROM user
WHERE 1=1
<if test="name != null">
AND name = #{name}
</if>
<if test="age != null">
AND age = #{age}
</if>
<if test="email != null">
AND email = #{email}
</if>
<where>
<if test="status != null">
AND status = #{status}
</if>
<if test="createTime != null">
AND create_time = #{createTime}
</if>
</where>
</select>
在这个例子中,
原文地址: https://www.cveoy.top/t/topic/gPYM 著作权归作者所有。请勿转载和采集!