1.Java中组装好
在Java中,把like的内容组装好,把这个内容传入sql语句.
public List<Student> quaryByName1(String uname) {
String name = "%" + uname +"%";//Java中组装好
return crudDao.quaryByName1(name);
}
<select id="quaryByName1" resultType="com.example.springboormybatis.mybatis.entity.Student">
select * from student where `name` like #{
name}
</select>
2.sql语句中
select * from student where `name` like concat("%",#{
name},"%")
或
select * from student where `name` like "%" #{
name} "%"