模糊查询
UserMapper.xml
<select id="getUserbyName" parameterType="String" resultType="user">
select * from mybatis.user where name like #{username}
</select>
UserMapper
//根据名字模糊匹配
public ArrayList<User> getUserbyName(String name);
UserDaoTest
@Test
public void testGetUserByName(){
//第一步:获得sqlSession对象
SqlSession sqlSession = MybatisUtils.getSqlSession();
//第二步:执行sql
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
ArrayList<User> userList = mapper.getUserbyName("%乔%");
for (User user : userList) {
System.out.println(user);
}
//第三步:关闭sqlSession
sqlSession.close();
}