模糊查询like两种使用方式

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} "%"

猜你喜欢

转载自blog.csdn.net/weixin_55806809/article/details/121277153