需求:查出给定id的记录: <select id="getEmpsByConditionForeach" resultType="com.test.beans.Employee"> SELECT * FROM tb1_emplyee WHERE id IN <foreach collection="list" item="item_id" separator="," open="…
<select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE <if test="state != null"> state = #{state} </if> <if test="title != null"> AND title like #{title} </if> <…
1.MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑. 2.MyBatis中用于实现动态SQL的元素主要有 if choose(when,otherwise) trim where set foreach 可以看出MyBatis的动态SQL的标签元素和接近JSP中的JSTL语法,下面我就分别详细的介绍一下 3.动态SQL中if的用法 <?xml version="1.0" encoding="UTF-8" ?&g…