zoukankan      html  css  js  c++  java
  • ReflectionException: There is no getter for property named

    在使用 Mybatis 时发生了一个 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ids' in 'class java.lang.String' 的异常

    案例如下:

     Mapper.java 文件代码:

    1     /**
    2      * 根据id值,删除用户
    3      * @param ids 用户id,可以是多个
    4      * @return  删除成功返回删除的数据库记录数量
    5      */
    6     Integer deleteUsers(String ids);

     Mapper.xml 文件代码:

    1     <!-- 删除多个用户 -->
    2     <delete id="deleteUsers" parameterType="java.lang.String">
    3         UPDATE
    4             user
    5         SET
    6             del_flag = 1
    7         WHERE
    8             user_id in (${ids})
    9     </delete>

    解决办法:

    1.在 Mapper.java 文件的抽象方法参数上添加 @Param("ids") 注解

    2.在 Mapper.xml 文件中删除 parameterType 属性

    3.在 Mapper.xml 文件中注入值时使用 param0 

    4. Mapper.xml 文件中使用 foreach 标签

     1      <!-- 删除多个用户 -->
     2      <delete id="deleteUsers" parameterType="java.lang.String">
     3          UPDATE
     4              user
     5          SET
     6              del_flag = 1
     7          WHERE
     8              user_id in 
     9                 <foreach item="item" collection="list" index="index" open="(" close=")" separator=",">
    10                     #{item}
    11                 </foreach>
    12      </delete>
  • 相关阅读:
    html表格,table标签
    2-3VRP的基本配置
    6 sys模块
    3 datetime模块
    2 time模块
    1 模块和包的介绍
    12 函数进阶---生成器
    13 函数进阶---迭代器
    10 函数进阶---闭包
    11 函数进阶---装饰器
  • 原文地址:https://www.cnblogs.com/xiao-lin-unit/p/13753910.html
Copyright © 2011-2022 走看看