sql

    <select id="selectDistinctVehicleOrders" resultType="String">
        SELECT vehicle_allocation_order
        FROM pan_scan
        <where>
            is_submit = 1
            AND vehicle_allocation_order != ''
            <if test="@org.apache.commons.lang.StringUtils@isNotBlank(dto.allotInWarehouse)">
                AND allot_in_warehouse = #{dto.allotInWarehouse,jdbcType=VARCHAR}
            </if>

            <if test="@org.apache.commons.lang.StringUtils@isNotBlank(dto.commitUser)">
                AND commit_user = #{dto.commitUser,jdbcType=VARCHAR}
            </if>

            <if test="dto.startTime != null">
                AND commit_time >= #{dto.startTime}
            </if>

            <if test="dto.endTime != null">
                AND commit_time <= #{dto.endTime}
            </if>

            <if test="@org.apache.commons.lang.StringUtils@isNotBlank(dto.vehicleAllocationOrder)">
                AND vehicle_allocation_order = #{dto.vehicleAllocationOrder}
            </if>
        </where>

        GROUP BY vehicle_allocation_order -- 代替 DISTINCT
        ORDER BY MAX(commit_time) DESC -- 选最新的 create_tm 排序
    </select>

报错:

03-10 13:50:29.137 ERROR  [] [1C8265035C3644B9A380F81DF4CF0BE9] [c.cf.newbarcode.api.handler.GlobalExceptionHandler]  - GlobalException
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='mybatis_plus_first', mode=IN, javaType=long, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 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 (1 > number of parameters, which is 0).
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
    at com.sun.proxy.$Proxy125.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:121)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:85)

 Response响应: ; payload = {"msg":"nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='mybatis_plus_first', mode=IN, javaType=long, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 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 (1 > number of parameters, which is 0).","code":1,"data":null}

这个问题卡了我半天,而且有个神奇的点在于只要传入的任意参数有值,就不会报错,解决方法,去掉里面的注释

        GROUP BY vehicle_allocation_order -- 代替 DISTINCT
        ORDER BY MAX(commit_time) DESC -- 选最新的 create_tm 排序

参考链接:https://blog.csdn.net/daming1/article/details/107336871

分类: java

0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注

站点统计

  • 文章总数:320 篇
  • 分类总数:20 个
  • 标签总数:193 个
  • 运行天数:1236 天
  • 访问总数:346125 人次

浙公网安备33011302000604

辽ICP备20003309号