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 模糊查询 中文问题的更多相关文章

  1. Ibatis/Mybatis模糊查询

    Ibatis/Mybatis模糊查询 根据网络内容整理 Ibatis中 使用$代替#.此种方法就是去掉了类型检查,使用字符串连接,不过可能会有sql注入风险. Sql代码 select * from ...

  2. MyBatis模糊查询相关

    Mybatis模糊查询的实现不难,如下实例:在UserMapper.xml中根据用户名模糊查询用户: <!-- 模糊查询用户 --> <select id="findSom ...

  3. MyBatis模糊查询不报错但查不出数据的一种解决方案

    今天在用MyBatis写一个模糊查询的时候,程序没有报错,但查不出来数据,随即做了一个测试,部分代码如下: @Test public void findByNameTest() throws IOEx ...

  4. MyBatis——模糊查询

    在mybatis中可以使用三种模糊查询的方式: <!-- 模糊查询 --> <select id="selectListByTitle" parameterTyp ...

  5. mybatis模糊查询防止SQL注入

    SQL注入,大家都不陌生,是一种常见的攻击方式.攻击者在界面的表单信息或URL上输入一些奇怪的SQL片段(例如“or ‘1’=’1’”这样的语句),有可能入侵参数检验不足的应用程序.所以,在我们的应用 ...

  6. Mybatis 模糊查询 like【笔记】Could not set parameters for mapping

    当使用mybatis 做模糊查询时如果这样写 会报 Could not set parameters for mapping: ParameterMapping{property='keywords' ...

  7. MyBatis 模糊查询的 4 种实现方式

    引言 MyBatis 有 4 种方式可以实现模糊查询. 员工信息表 ( tb_employee ) 如下: id name sex email birthday address 001 张一凡 男 z ...

  8. Mybatis模糊查询结果为空的解决方案

    写在前面 Mybatis使用模糊查询,查询结果为空的解决方案,我的代码是 select * from sp_user where 1=1 <if test="username!=nul ...

  9. mybatis模糊查询

    今天遇到一个模糊查询的问题,需求是:根据传入的时间查询当天的所有数据,解决办法是使用$或者contact,具体sql模拟如下: select * from table_name where creat ...

随机推荐

  1. 空指针错误 java.lang.NullPointerException

    使用基本的JAVA数据类型,变量的值要么已经是默认值,如果没有对其正常赋值,程序便 不能通过编译,因此使用基本的JAVA数据类型(double,float,boolean,char,int,long) ...

  2. Windows编译安装mod_wsgi,配合使用Django+Apahce

    编译环境: 均是32位版本 Microsoft Visual Studio 10.0 Microsoft SDKs v7.1 Apache2.4 Python3.4 mod_wsgi-4.5.0 要求 ...

  3. SVM支持向量机算法

    支持向量机(SVM)是另一类的学习系统,其众多的优点使得他成为最流行的算法之一.其不仅有扎实的理论基础,而且在许多应用领域比大多数其他算法更准确.  1.线性支持向量机:可分情况 根据公式(1)< ...

  4. linux 命令实现原理

    我们知道有些Linux的命令涉及到一些高效率的算法,在此做出一个积累吧,不是系统的. 1.tail命令打印一个文件的最后num行 2.grep命令从文本中匹配字符串 基于正则表达式的匹配很快. it ...

  5. CentOS服务端口开放

    #例如开放81端口iptables -I INPUT -i eth0 -p tcp --dport 81 -j ACCEPTiptables -I OUTPUT -o eth0 -p tcp --sp ...

  6. hdu_2546_饭卡(01背包)

    题目连接:hdu_2546_饭卡 题意:中文,不解释 题解:先拿5元来买最贵的,最后就是一个01背包,这里也算用到贪心的思想 #include<bits/stdc++.h> #define ...

  7. Android media媒体库分析之:MediaProvider

    在做Android媒体应用程序时(Audio.Image.Video)需要对Android的媒体提供者(MediaProvider)做详细的分析,下面记录一下我的收获: 一.获取MediaProvid ...

  8. Sasha and Array

    Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard inp ...

  9. Preface

    I'd never given much thought to how I would die — 我从来没有想过我会怎么样死 much thought 仔细思考 我从未仔细思考过,我将如何死去 th ...

  10. smarty(原理概述)

    转自:http://www.cnblogs.com/RightDear/archive/2012/11/06/2756218.html smarty(模板引擎,模板技术) 使用smarty主要是为了实 ...