当前位置: 首页 > article >正文

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

问题描述

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

sharding sphere 版本 5.3.2

xml 文件SQL 语句:

<select id="countSchoolByStatus" parameterType="java.lang.Integer" resultType="int">
        select
        count(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: select
        count(id)
        from school
         WHERE  `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">
        select
        count(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>

http://www.kler.cn/news/360734.html

相关文章:

  • OBOO鸥柏:液晶拼接大屏搭载节点盒分布式集中管控控制系统新技术
  • 2024年软件设计师中级(软考中级)详细笔记【7】面向对象技术(上)(分值10+)
  • Java项目-基于springboot框架的网上书城系统项目实战(附源码+文档)
  • jQuery:元素控制 事件
  • ReactOS寻找病返回最小StartingAddress所在结点。
  • 【Flutter】iOS上使用 UIPasteboard.detectPatterns 优化剪切板权限弹窗逻辑
  • centos 安装达梦数据库
  • Oracle分区表改造(三):通过分区交换和分裂改造为分区表
  • 苦寻多时,终于找到!这款免费GIS工具助你轻松搞定地形切片
  • [Luogu 4630] APIO2018 铁人两项(广义圆方树)
  • 【含文档】基于Springboot+Vue的旅游信息管理系统(含源码+数据库+lw)
  • 如何理解 PHP 中的注释
  • C++和OpenGL实现3D游戏编程【连载16】——详解三维坐标转二维屏幕坐标(向量和矩阵操作实战)
  • 同程旅行面经
  • 基于Springboot+Vue的人事档案管理系统的设计与实现 (含源码数据库)
  • 1、opencv图像基本处理方法
  • [Unity Demo]从零开始制作空洞骑士Hollow Knight第十五集:制作更多地图,更多敌人,更多可交互对象
  • 如何将两个同样大小的List组装成一个Map?
  • 【学习笔记】网络设备(华为交换机)基础知识 9 —— 堆叠配置
  • 【原创】java+ssm+mysql校园在线答疑管理系统设计与实现