Mybatis学习:配置Mapper配置文件中的sql的一个例子的分析
mybatis学习文档:by 春晓推荐https://blog.csdn.net/luanlouis/article/details/40422941
示例:
解析:
<if test="min_salary != null"> where SALARY < #{min_salary,jdbcType=DECIMAL} </if>
if test="min_salary != null":代表如果min_salary为空(min_salary 没有值) 就不拼接里面的语句(就不执行后面的where)
where SALARY < #{min_salary,jdbcType=DECIMAL}:代表 SALARY小于你传进来的值min_salary,jdbcType代表参数min_salary的类型;
#{}:代表取出你传进来的参数min_salary对应的值
<select id="selectByMinSalary" resultMap="BaseResultMap" parameterType="java.util.Map" > select EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, SALARY from LOUIS.EMPLOYEES <if test="min_salary != null"> where SALARY < #{min_salary,jdbcType=DECIMAL} </if> </select>