java小菜机一枚 2023-08-11 12:38 采纳率: 91.3%
浏览 7
已结题

Parameter 'major' not found. Available parameters are [majorList, param1]

nested exception is org.apache.ibatis.binding.BindingException: Parameter 'major' not found. Available parameters are [majorList, param1]

我在写批量修改的时候遇到的问题,我这里给了@Param但是还是会出现这个问题。其他代码都没问题
majorMapper.java

    List<Major> batchUpdateMajor(@Param("majorList") List<Major> majorList)

majorMapper.xml

<update id="batchUpdateMajor" parameterType="com.guli.collegemanagetrailing.entity.Major">
        UPDATE `major`
        <trim prefix="SET" suffixOverrides=",">
            <if test="major.majorName != null and major.majorName != ''">
                `major_name` = #{major.majorName},
            </if>
            <if test="major.collegeId != null">
                `college_id` = #{major.collegeId},
            </if>
            <if test="major.number != null">
                `number` = #{major.number},
            </if>
            <if test="major.status != null">
                `status` = #{major.status},
            </if>
        </trim>
        <where>
            <foreach collection="majorList" item="major" separator="OR">
                <if test="major.id != null">
                    `id` = #{major.id}
                </if>
            </foreach>
        </where>
    </update>

collegeServiceImpl.java

@Override
    @Transactional
    public void deleteCollege(Integer id) {
        if (NumberUtils.isEmpty(id)) {
            throw new CustomException(ResultEnum.notParamError.getCode(),ResultEnum.notParamError.getMessage());
        }
        College collegeById = collegeMapper.getCollegeById(id);
        if (ObjectUtils.isEmpty(collegeById)) {
            throw new CustomException(ResultEnum.collegeNotExist.getCode(),ResultEnum.collegeNotExist.getMessage());
        }
        // 删除学院前先查询有没有专业绑定,如果有专业绑定当前学院则把专业的collegeId改为0
        List<Major> majorListById = collegeMapper.getMajorListById(id);
        if (!ObjectUtils.isEmpty(majorListById) || !Objects.equals(majorListById.size(),StatusCode.userStatus.getStatus())) {
            // 批量修改专业的学院id
            for (Major major : majorListById) {
                major.setCollegeId(StatusCode.userStatus.getStatus());
            }
            majorMapper.batchUpdateMajor(majorListById);
        }
        Integer deleteCollege = collegeMapper.deleteCollege(id);
        if (!Objects.equals(deleteCollege,StatusCode.recordCount.getStatus())) {
            throw new CustomException(ResultEnum.deleteAllUnSuccessful.getCode(),ResultEnum.deleteUnSuccessful.getMessage());
        }
    }
  • 写回答

2条回答 默认 最新

  • i__0o0__ 2023-08-11 13:39
    关注

    你这入参是个list,xml中的parameterType也应该是个list啊,这个xml中的sql并不能自动遍历list,它只是被动接受参数,还是要自己处理的。
    得自己遍历list,在遍历中组织sql

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月19日
  • 已采纳回答 8月11日
  • 创建了问题 8月11日

悬赏问题

  • ¥15 C++ 菜单窗口独立出来,可以随意移动放大缩小。
  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 网友们我该怎么办啊,急
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?