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

Parameter index out of range (2 > number of parameters, which is 1【已解决】

文章目录

  • 1、SysLogMapper.xml添加注释导致的
  • 2、解决方法
  • 3、总结

1、SysLogMapper.xml添加注释导致的

    <!--定义一个查询方法,用于获取日志列表--><!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto--><select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">/*查询语句,通过join操作查询sys_log和sys_user表的数据*//*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id/*使用where子句过滤查询条件*/<where>/*如果LogDto中的userId不为空,则添加过滤条件b.id = #{userId}*/<if test="userId != null">b.id = #{userId}</if>/*如果LogDto中的logMsg不为空,则添加过滤条件log_msg like concat('%',#{logMsg},'%')*//*使用concat函数和like操作符实现模糊查询*/<if test="logMsg != null and logMsg.trim() != ''">and log_msg like concat('%',#{logMsg},'%')</if></where>/*按照id降序排序排列查询结果*/order by id desc</select>

在这里插入图片描述

java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='userId', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89)at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
Caused by: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:55)at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)... 59 more
Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)

2、解决方法

把注释去掉

    <!--定义一个查询方法,用于获取日志列表--><!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto--><select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">/*查询语句,通过join操作查询sys_log和sys_user表的数据*//*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id/*使用where子句过滤查询条件*/<where><if test="userId != null">b.id = #{userId}</if><if test="logMsg != null and logMsg.trim() != ''">and log_msg like concat('%',#{logMsg},'%')</if></where>/*按照id降序排序排列查询结果*/order by id desc</select>

想加注释也可以,可以用下面这种方式:

    <!--定义一个查询方法,用于获取日志列表--><!--方法ID为getLogList,返回类型com.main.server.api.model.SysLogModel,参数类型为com.main.server.api.dto.LogDto--><select id="getLogList" resultType="com.main.server.api.model.SysLogModel" parameterType="com.main.server.api.dto.LogDto">/*查询语句,通过join操作查询sys_log和sys_user表的数据*//*根据log_user_id和id关联sys_log和sys_user表,获取用户名*/select a.*,b.real_name as user_name from sys_log a join sys_user b on a.log_user_id = b.id/*使用where子句过滤查询条件*/<where><!--如果LogDto中的userId不为空,则添加过滤条件b.id = #{userId}--><if test="userId != null">b.id = #{userId}</if><!--如果LogDto中的logMsg不为空,则添加过滤条件log_msg like concat('%',#{logMsg},'%')--><!--使用concat函数和like操作符实现模糊查询--><if test="logMsg != null and logMsg.trim() != ''">and log_msg like concat('%',#{logMsg},'%')</if></where>/*按照id降序排序排列查询结果*/order by id desc</select>

3、总结

在xml中,注释尽量用下面这种的

<!-- -->
这种注释形式被称为 HTML 注释。它用于在 HTML 代码中添加注释,注释的内容不会在网页中显示,仅作为开发人员的备注或用于临时禁用部分 HTML 代码。
http://www.lryc.cn/news/406476.html

相关文章:

  • rk3588s 定制版 USB adb , USB2.0与USB3.0 区别,adb 由typeC 转换到USB3.0(第二部分)
  • Cookie与Session 实现登录操作
  • 通过IEC104转MQTT网关轻松接入阿里云平台
  • lua 游戏架构 之 游戏 AI (五)ai_autofight_find_way
  • vue3+openLayers点击标记事件
  • 深入分析 Android ContentProvider (三)
  • 养宠浮毛异味双困扰?性价比高的宠物空气净化器推荐
  • maven项目容器化运行之3-优雅的利用Jenkins和maven使用docker插件调用远程docker构建服务并在1Panel中运行
  • docker 打包orbbec
  • 无涯·问知财报解读,辅助更加明智的决策
  • 【Apache Doris】数据副本问题排查指南
  • 【HarmonyOS】关于鸿蒙消息推送的心得体会(二)
  • 零基础入门:创建一个简单的Python爬虫管理系统
  • 【Node.js基础04】node.js模块化
  • 数据库——单表查询
  • dsa加训
  • SpringBoot源码(1)ApplicationContext和BeanFactory
  • CANoe编程实例--TCP/IP通信
  • Neuron协议网关的北向应用插件开发
  • 【BUG】已解决:You are using pip version 10.0.1, however version 21.3.1 is available.
  • electron-builder打包vue2项目不显示element-ui图标
  • controller层-请求格式为json-请求方法为get
  • 【Linux】网络通信基础:应用层协议、HTTP、序列化与会话管理
  • @NotNull、@NotEmpty 和 @NotBlank 区别
  • 大模型应用—大模型赋能网络爬虫
  • 在 Qt 中获取 MouseMove 事件
  • 自动驾驶系列—智能巡航辅助功能中的路口通行功能介绍
  • 如何为WordPress网站设置多语言站点
  • 【RHCE】综合真机实验(shell完成)
  • 【Python】成功解决conda创建虚拟环境时出现的CondaHTTPError: HTTP 000 CONNECTION FAILED错误