//随便来一段SQL语句
<select id="queryByCondition3" resultMap="BaseResultMap" parameterType="com.zhr.pojo.Emp">
select * from emp
<where>
<if test="empName != null and empName != '' ">
and emp_name = #{empName}
</if>
<if test="empSal != null and empSal != 0">
and emp_sal >= #{empSal}
</if>
<if test="empHiredate != null">
and emp_hiredate = #{empHiredate}
</if>
</where>
</select>
//取其一:and emp_name = #{empName}
//当你把and 和 emp_name 之间用Tab隔开 保准出错!(此处Tab键 和 空格键 距离是一样的)
//一个可以把你整疯的错误,希望对大家有帮助!
博客展示了一段MyBatis中的SQL语句,用于根据条件查询员工信息。同时指出在该SQL语句里,若将and和字段名之间用Tab键隔开会导致出错,提醒大家注意此易被忽视的问题。
2485

被折叠的 条评论
为什么被折叠?



