mysql模糊查询总是查不到_用mybatis进行模糊查询总是查不到结果!

//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查询,

不知道原因,日后研究

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值