<select id="findBySalary" parameterType="com.tarena.entity.Condition"
resultType="com.tarena.entity.Emp">
select * from t_emp
<choose>
<when test="salary>2000">
where sal>#{salary}
</when>
<otherwise>
where sal>=2000
</otherwise>
</choose>
</select>
怎样理解这段话,是查询工资大于等于2000的员工信息。这是固定格式吗?怎样翻译?不管外界传入什么值好像都没有什么影响。执行流程怎么判断。比如说工资输入800呢怎么判断3000呢?
工资输入800 符合第一种情况,出来的sql就是
select * from t_emp where sal>=2000
select * from t_emp where sal>#{salary}(salary>2000")
select * from t_emp where sal>2000(salary<2000" )
这就是你的SQL语句。
其实就是:
1。salary>2000
where sal > nnn
1。salary>2000
select * from t_emp where sal > nnn