Mybatis 模糊查询 中文问题
IDE编码:GBK ,换成UTF-8也不行!
@Test
public void testSearchStudents() {
logger.info("查询学生(带条件)");
Map<String,Object> map=new HashMap<String,Object>();
//map.put("gradeId", 2);
map.put("name", "王"); // 中文
//map.put("name", "a"); 英文
//map.put("age", 17);
List<Student> studentList=studentMapper.searchStudents(map);
for(Student student:studentList){
logger.info(student);
}
}
<select id="searchStudents" parameterType="Map" resultMap="StudentResult">
select * from t_student
<where>
<if test="gradeId!=null">
gradeId=#{gradeId}
</if>
<if test="name!=null">
<!-- and name like '%${name}%' -->
and name like CONCAT('%','${name}','%' )
</if>
<if test="age!=nulll">
and age=#{age}
</if>
</where>
</select>
假设模糊查询name=英文,可以打印学生信息;但是模糊查询name=中文,查询不到信息。
我的解决方案是:原来是数据库编码的问题,简单的方法是:在.properties配置文件中的jdbc.url值后面跟上?useUnicode=true&characterEncoding=utf8
注意:前提环境:Mybatis没有和SpringMvc整合,整合后不需要这样设置,可以有其他更便捷的方法。(纯粹个人理解,希望可以得到更多人的指教)
Mybatis 模糊查询 中文问题的更多相关文章
- Ibatis/Mybatis模糊查询
Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from ...
- MyBatis模糊查询相关
Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...
- MyBatis模糊查询不报错但查不出数据的一种解决方案
今天在用MyBatis写一个模糊查询的时候,程序没有报错,但查不出来数据,随即做了一个测试,部分代码如下: @Test public void findByNameTest() throws IOEx ...
- MyBatis——模糊查询
在mybatis中可以使用三种模糊查询的方式: <!-- 模糊查询 --> <select id="selectListByTitle" parameterTyp ...
- mybatis模糊查询防止SQL注入
SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...
- Mybatis 模糊查询 like【笔记】Could not set parameters for mapping
当使用mybatis 做模糊查询时如果这样写 会报 Could not set parameters for mapping: ParameterMapping{property='keywords' ...
- MyBatis 模糊查询的 4 种实现方式
引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...
- Mybatis模糊查询结果为空的解决方案
写在前面 Mybatis使用模糊查询,查询结果为空的解决方案,我的代码是 select * from sp_user where 1=1 <if test="username!=nul ...
- mybatis模糊查询
今天遇到一个模糊查询的问题,需求是:根据传入的时间查询当天的所有数据,解决办法是使用$或者contact,具体sql模拟如下: select * from table_name where creat ...
随机推荐
- CodeForces 696A Lorenzo Von Matterhorn (LCA + map)
方法:求出最近公共祖先,使用map给他们计数,注意深度的求法. 代码如下: #include<iostream> #include<cstdio> #include<ma ...
- haxe 中使用音效
将wavSound.wav音效文件放到assets/sounds下, 在project.xml加入以下代码: <assets path="assets/sounds" ren ...
- Ubuntu下安装Intellij IDEA和PyCharm
需要先安装JDK 官网下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载 ...
- IndentationError: unexpected indent python
都知道python是对格式要求很严格的,写了一些python但是也没发现他严格在哪里,今天遇到了IndentationError: unexpected indent错误我才知道他是多么的严格. 以后 ...
- hdu_2688_Rotate(树状数组)
题目连接:hdu_2688_Rotate 题意:给你n数,(n<=3e6),有两个操作,Q为 当前有多少对数,满足严格递增,R l,r为旋转l,r这个区间的数 题解:求严格递增的顺序对我们可以反 ...
- Request 地址栏传值
request页面 protected void btnSearch_Click(object sender, EventArgs e) { Response.Redirect("Reque ...
- 两种不同的重置样式方法(normalize.css)
重置样式非常多,凡是一个前端开发人员肯定有一个常用的重置CSS文件并知道如何使用它们.他们是盲目的在做还是知道为什么这么做呢?原因是不同的浏览器对一些元素有不同的默认样式,如果你不处理,在不同的浏览器 ...
- Cells Not Under Attack
Cells Not Under Attack Vasya has the square chessboard of size n × n and m rooks. Initially the ches ...
- angularJs关于指令的一些冷门属性
我们使用ng的时候,经常会使用到指令,大家所熟知的属性我在这里就不介绍了,讲讲大家没怎么留意的属性 1.multiElement 这是指定指令作用区间的功能,最常用的就是ng-repeat-start ...
- pycharm 安装venv的依赖包
(venv)$ pip install -r requirements.txt