//IStudentDao.xml
@Overridepublic ListselectStudentByName(String name) {
SqlSession sqlSession= null;
List list = null;try{
sqlSession=MySqlSession.getSqlSession();
list= sqlSession.selectList("selectList",name);
}catch(IOException e) {
e.printStackTrace();
}finally{if(sqlSession!=null){
sqlSession.close();
}
}returnlist;
}
test类里
@Test
public void test08()
{
IStudentDao studentDao = new IStudentDaoImpl();
List students = studentDao.selectStudentByName("三");
System.out.println("查找成功!");
for (Student student:
students) {
System.out.println(student);
}
}
IStudentDao.xml(映射文件)
/p>
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select* from student where name like '%' #{name} '%'
为了进行模糊查询,结果总是查询不到结果!!!
分析:
代码没问题,表中也有数据,sql语句放在数据库中也能查询到结果也没问题,
那就是连接的问题,仔细查了一遍也没问题!但是第二天本来要放弃,又找了个帮我看,没看出来,他想要走的时候我试试在连接处添加一个?characterEncoding=utf8,因为我的数据库原本就有编码问题
...
最初的时候插入数据就乱码。
这个地方出错源自于我潜意识里觉得查询时乱码不会影响查询结果,最后我错了。
最后数据库编码问题会影响插入,修改,模糊查询,复合条件查询中带有like '%x%' 的。但不影响进行所有查询,根据id查询,
不知道原因,日后研究