zoukankan      html  css  js  c++  java
  • 【Mybatis异常】Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

    一、错误原因分析

    从错误提示可以看出:实际传入的参数大于sql中待设置的参数,也就是sql中的?少于参数或?根本没有
    产生原因:

     ?号被单引号包围

    如:

    sql += " and article_title like '%#{articleTitle}%'";

    二、解决办法

    去掉单引号

    上面sql改为:

    sql += " and article_title like concat('%',#{articleTitle},'%')";

    三、范式

        <select id="findAllByKeywords" resultType="CheckItem">
            SELECT <include refid="all"/> from <include refid="table"/>
            <where>
            <if test="keywords != null and keywords.length > 0">
            code like concat('%',#{keywords},'%') or name like concat('%', #{keywords}, '%')
            </if>
            </where>
        </select>
  • 相关阅读:
    shell循环
    shell选择语句
    shell运算符
    shell变量
    前端基础复习
    flask 模板
    flask 会话技术
    flask 项目结构
    Tornado 框架介绍
    flask-models 操作
  • 原文地址:https://www.cnblogs.com/powerbear/p/14724835.html
Copyright © 2011-2022 走看看