1. 参数中直接加入%%
Employee employee = new Employee();
// 设置模糊查询的参数
employee.setName("%o%");
<select id="selectEmployeeLikeName" resultType="org.fkit.domain.Employee"> SELECT * FROM tb_employee WHERE loginname LIKE #{name} </select>
2. bind标签
<select id="selectEmployeeLikeName" resultType="org.fkit.domain.Employee"> <bind name="pattern" value="'%' + _parameter.getName() + '%'" /> SELECT * FROM tb_employee WHERE loginname LIKE #{pattern} </select>
3. CONCAT
<select id="selectEmployeeLikeName" resultType="org.fkit.domain.Employee"> SELECT * FROM tb_employee WHERE loginname LIKE concat('%',#{name},'%') </select>
4."%"#{name}"%"
<select id="selectEmployeeLikeName" resultType="org.fkit.domain.Employee"> SELECT * FROM tb_employee WHERE loginname LIKE "%"#{name}"%" </select>
备注:以上4种方法适用于MySQL,有说like '%'||#{name}||'%'在MySQL中是实现不了的。