关于where标签中and的位置问题
- 正确格式
<select id="selectUserBySexAndUserName" resultMap="UserExample" parameterType="com.huarenwenyu.client.dao.UserExample">
select * from user
<where>
<if test="sex != null and sex != ''">
sex = #{sex} and
</if>
<if test="username != null and username != ''">
username = #{username}
</if>
</where>
</select>
- 错误格式
<select id="selectUserBySexAndUserName" resultMap="UserExample" parameterType="com.huarenwenyu.client.dao.UserExample">
select * from user
<where>
<if test="sex != null and sex != ''">
sex = #{sex}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
</where>
</select>
报错:###SQL: select*from user WHERE sex = ? and
WHERE标签去默认会去掉第一个前and。