欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > sharding sphere 加解密功能 like语句 SQL 解析报错

sharding sphere 加解密功能 like语句 SQL 解析报错

2024/10/25 22:40:02 来源:https://blog.csdn.net/u010657094/article/details/143040234  浏览:    关键词:sharding sphere 加解密功能 like语句 SQL 解析报错

问题描述

应用在使用 sharding sphere 来实现加密后,对于 like sql 语句解析抛异常,异常信息如下:

sharding sphere 版本 5.3.2

xml 文件SQL 语句:

<select id="countSchoolByStatus" parameterType="java.lang.Integer" resultType="int">selectcount(id)from school<where><if test="status != null">and `status` = #{status, jdbcType=INTEGER}</if><if test="name != null">and `name` like '%' #{status, jdbcType=INTEGER} '%'</if></where></select>
Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: org.apache.shardingsphere.sql.parser.exception.SQLParsingException: You have an error in your SQL syntax: selectcount(id)from schoolWHERE  `status` = ?and `name` like '%' ? '%', no viable alternative at input '?' at line 7, position 36, near [@15,136:136='?',<42>,7:36]at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) ~[mybatis-spring-1.3.2.jar:1.3.2]at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) ~[mybatis-spring-1.3.2.jar:1.3.2]at com.sun.proxy.$Proxy59.selectOne(Unknown Source) ~[na:na]at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) ~[mybatis-spring-1.3.2.jar:1.3.2]

解决方案

修改 like % % 的写法,改为 like concat()

<select id="countSchoolByStatus" parameterType="java.lang.Integer" resultType="int">selectcount(id)from school<where><if test="status != null">and `status` = #{status, jdbcType=INTEGER}</if><if test="name != null">and `name` like concat('%', #{status, jdbcType=INTEGER}, '%')</if></where></select>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com