方法一
// 模糊查询
List<User> getUserLike(String str);
<select id="getUserLike" resultType="com.mao.pojo.User" parameterType="String">
select * from test.user where name like "%"#{str}"%"
</select>
@Test
public void testGetUserLike(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserDao mapper = sqlSession.getMapper(UserDao.class);
List<User> us = mapper.getUserLike("自定义");
for (User u : us) {
System.out.println(u.toString());
}
sqlSession.close();
}
方法二
<select id="getUserLike" resultType="com.mao.pojo.User" parameterType="String">
select * from test.user where name like #{str}
</select>
@Test
public void testGetUserLike(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserDao mapper = sqlSession.getMapper(UserDao.class);
List<User> us = mapper.getUserLike("%自定义%");
for (User u : us) {
System.out.println(u.toString());
}
sqlSession.close();
}
注意: