知識點:bind在模糊查詢中的用法
在我的博客 mybatis中使用mysql的模糊查詢字符串拼接(like) 中也涉及到bind的使用
<!-- List<Employee> getEmpsTestInnerParameter(Employee employee); -->
<select id="getEmpsTestInnerParameter" resultType="com.hand.mybatis.bean.Employee">
<!-- bind:可以將OGNL表達式的值綁定到一個變量中,方便后來引用這個變量的值 -->
<bind name="bindeName" value="'%'+eName+'%'"/> eName是employee中一個屬性值
SELECT * FROM emp
<if test="_parameter!=null">
where ename like #{bindeName}
</if>
</select>
測試類中:
Employee emp=new Employee();
emp.setEname("張"); 為eName屬性賦值為“張”
List<Employee> list=mapper.getEmpsTestInnerParameter(emp);
for (Employee employee : list) {
System.out.println(employee);
}