<!--第一种 like , java代码指定 like的内容--><selectid="selectLikeOne"resultType="com.bjpowernode.domain.Student">
select id,name,email,age from student where name like #{name}
</select><!--第二种方式:在mapper文件中拼接 like的内容--><selectid="selectLikeTwo"resultType="com.bjpowernode.domain.Student">
select id,name,email,age from student where name like "%" #{name} "%"
</select>
二:方法的调用
@Test/**
* 第一种 like , java代码指定 like的内容
*/publicvoidtestSelectLikeOne(){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);//准备好like的内容
String name ="%李%";
List<Student> students = dao.selectLikeOne(name);for(Student stu: students){
System.out.println("#######学生="+stu);}
sqlSession.close();}@Test/**
* 第二种方式:在mapper文件中拼接 like的内容
*/publicvoidtestSelectLikeTwo(){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);//准备好like的内容
String name ="张";
List<Student> students = dao.selectLikeTwo(name);for(Student stu: students){
System.out.println("*******学生="+stu);}
sqlSession.close();}