mybatis 中文做参数报错

  一个简单的查询,如果参数中有中文。如下:

<select id="xxxx" resultType="hashmap">
    select * from talbe_a a where  a.kpeople = ${name}
</select>

报错:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "萧亚轩": 标识符无效...

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "萧亚轩": 标识符无效....

mybatis sql日志:

18:06:36,192 DEBUG JdbcTransaction:47 - Openning JDBC Connection
18:06:36,830 DEBUG PooledDataSource:47 - Created connection 1459361227.
18:06:36,843 DEBUG queryrealactormediatop:47 - ooo Using Connection [[email protected]]
18:06:36,843 DEBUG queryrealactormediatop:47 - ==>  Preparing: select * from table_a a where v1.kpeople = 萧亚轩
18:06:36,961 DEBUG queryrealactormediatop:47 - ==> Parameters: 

注意:“萧亚轩”两边没有单引号,不是“?”的占位符,参数列表里面是没有值。

修改其实很简单:

v1:换$ 为#

<select id="xxxx" resultType="hashmap">
    select * from talbe_a a where  a.kpeople = #{name}
</select>

v2:添加 ‘’ 单引号

<select id="xxxx" resultType="hashmap">
    select * from talbe_a a where  a.kpeople = ‘${name}‘
</select>

#只会当成个字符串

$就不一定是字符串,或者其他类型

时间: 2024-08-04 15:45:19

mybatis 中文做参数报错的相关文章

jQuery 之 setTimeout 传递字符串参数报错

当你打算调用一些jQuery代码显示隐藏的一个元素,并调用setTimeout()在一段延时之后设置其HTML的内容: 整个页面的代码是这样的. <span style="font-size:18px;"><html> <head> <title></title> </head> <body> <a href="#" id='heihei' onclick="show

单元测试时候使用[ClassInitialize]会该方法必须是静态的公共方法,不返回值并且应采用一个TestContext类型的参数报错的解决办法

using Microsoft.VisualStudio.TestTools.UnitTesting; 如果该DLL应用的是 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 版本为9.0.0.0 的话,则使用[ClassInitialize]会该方法必须是静态的公共方法,不返回值并且

python里面出现中文的时候报错 &#39;ascii&#39; codec can&#39;t encode characters in position

编码问题,在头部添加 import sys reload(sys) sys.setdefaultencoding( "utf-8" ) http://www.xuebuyuan.com/2226637.html python里面出现中文的时候报错 'ascii' codec can't encode characters in position

【spring mvc】后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Speci

mybatis配置,idea报错:java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test

报错信息: "C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=54826:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C

fastjson自动转化参数报错

开发环境:spring-mvc4.1.7.fastjson1.2.7 问题描述:系统采用的前后端完全分离方式,前端页面使用ajax调用后台服务时,想用fastjson自动转化请求参数对象. // 前端调用$.ajax({ url : "bas/test.do", type : "POST", async : true, contentType : "application/json; charset=utf-8", data : country,

Mybatis映射.xml文件报错

MyBatis框架里面,在dao层进行测试,控制台显示错误是:必须为元素类型 "delete" 声明属性 "resultType" 相应的.xml文件的sql语句是: 控制台的详细报错是: 1.必须为元素类型 "delete" 声明属性 "resultType" 2. 上网查资料说,每一个_sqlMapper.xml文件中尽量每中sql语句对一个namespace(每个dao层的完整java类):结果尝试,也没有成功: 最后索

发现个delphi调用vc写的Dll中包含pchar参数报错奇怪现象

发现个delphi调用vc写的Dll中包含pchar参数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会运行错,在之前任意加上条语句就不报错了奇怪! vc的DLL源码地址 http://blog.csdn.net/lqena/article/details/46357165 Delphi源码如下: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co

关于tomcat对编码不正确的url参数报错的解决

按照规范,url参数必须使用限定字符,其它字符需要进行编码,用像js的encodeurlcomponent函数. 在IE和360浏览器的兼容模式,不会自动对url的参数进行编码,会导致tomcat报错. 对浏览器参数进行编码就解决了问题. Stack Overflow上有问到这个,但是解答不正确,点支持的很少. 百度搜索结果也有提到,说要在nginx对请求进行编码. 原文地址:https://www.cnblogs.com/silvestris/p/12038063.html