【Mybatis】学习笔记01:连接数据库,实现增删改
【Mybatis】学习笔记02:实现简单的查
【MyBatis】学习笔记03:配置文件进一步解读(非常重要)
【MyBatis】学习笔记04:配置文件模板
【MyBatis】学习笔记05:获取参数值的两种方式
【MyBatis】学习笔记06:各种查询所返回数据的数据类型
目录/** * 根据用户名模糊查询 * @param username 用户名的关键字 * @return List<User> 用户列表 */ List<User> getUserByLike(@Param("username") String username);
<!-- List<User> getUserByLike(@Param("username") String username);--> <select id="getUserByLike" resultType="User"> select * from t_users where userName like "%${username}%" </select>
@Test public void testGetUserByLike(){ SqlSession sqlSession = SqlSessionUtils.getSqlSession(); SQLMapper mapper = sqlSession.getMapper(SQLMapper.class); List<User> list = mapper.getUserByLike("三"); System.out.println(list); }
[User{userId='5',userName='张三'userCount='mllt@xrilang.com',userPassword='123'userGrade='0',userRegDate='null'userBlance='0'}, User{userId='6',userName='李三'userCount='xirlang@mllt.c',userPassword='124'userGrade='0',userRegDate='null'userBlance='0'}]
<!-- List<User> getUserByLike(@Param("username") String username);--> <select id="getUserByLike" resultType="User"> <!-- select * from t_users where userName like "%${username}%"--> select * from t_users where userName like concat("%",#{username},"%") </select> <!--concat 拼接-->
[User{userId='5',userName='张三'userCount='mllt@xrilang.com',userPassword='123'userGrade='0',userRegDate='null'userBlance='0'}, User{userId='6',userName='李三'userCount='xirlang@mllt.c',userPassword='124'userGrade='0',userRegDate='null'userBlance='0'}]
<!-- List<User> getUserByLike(@Param("username") String username);--> <select id="getUserByLike" resultType="User"> <!-- select * from t_users where userName like "%${username}%"--> <!-- select * from t_users where userName like concat("%",#{username},"%")--> select * from t_users where userName like "%"#{username}"%" </select>
[User{userId='5',userName='张三'userCount='mllt@xrilang.com',userPassword='123'userGrade='0',userRegDate='null'userBlance='0'}, User{userId='6',userName='李三'userCount='xirlang@mllt.c',userPassword='124'userGrade='0',userRegDate='null'userBlance='0'}]