Fuzzy query for annotation development in MyBatis

Fuzzy query for annotation development in MyBatis

There are two ways to write fuzzy query in annotation development, one is to set a percent sign to the parameter itself when passing in the parameter

public interface IUserDao {
    
    
    @Select("select * from user where username like #{username}")
    List<User> queryAll(String username);
}

public void test1(){
    
    
        String username="%y%";
        List<User> users = iUserDao.queryAll(username);
        System.out.println(users);
    }

The second is to use the form of "%${value}%" in the annotated sql statement, where the value is fixed here, pay attention to the use of quotation marks, the code is as follows

  @Select("select * from user where username like '%${value}%' ")
  List<User> queryAll(String username);

 public void test1(){
    
    
        String username="y";
        List<User> users = iUserDao.queryAll(username);
        System.out.println(users);
    }

Guess you like

Origin blog.csdn.net/weixin_45925906/article/details/112718034