mybatis实现模糊查询

接口

 //模糊查询
    List<Cloud> getUserLike(String value);

 

UserMapper.xml

<!--    value是模糊查询的参数-->
    <select id="getUserLike" resultType="cloud">
        select * from caijing where word like "%"#{value}"%"
    </select>

 

测试类:

    @Test
    public void getCloudLike(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();

        UserDao mapper = sqlSession.getMapper(UserDao.class);

        List<Cloud> list = mapper.getUserLike("我");

        for (Cloud cloud : list) {
            System.out.println(cloud);
        }

        sqlSession.close();
    }

参数我也可写成%我%这样在sql中就不用写%了

 

posted @ 2021-12-10 12:44  天岁  阅读(54)  评论(0编辑  收藏  举报