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"); 英文
and age=#{age}
</if>
</where>
</select>
name=中文,查询不到信息。
我的解决方案是:原来是数据库编码的问题,简单的方法是:在.properties配置文件中的jdbc.url值后面跟上?useUnicode=true&characterEncoding=utf8
注意:前提环境:Mybatis没有和SpringMvc整合,整合后不需要这样设置,可以有其他更便捷的方法。(纯粹个人理解,希望可以得到更多人的指教)