mybatis的动态sql语句
where标签:起拼接作用,在原sql语句后添加where
if标签:起拼接作用,满足条件后,在sql语句后添加判断条件
如:
<select id="#" resultMap="#" parameterType="user">
select * from user_table
<where>
<if test="userName != null">
and user_name = #{userName}
</if>
<if test="userPass != null">
and user_pass = #{userPass}
</if>
</where>
</select>
如果userName != null为true,userPass != null为false
那么sql = select * from user_table where user_name = “#”;