Parameter ‘xxx‘ not found. Available parameters are [arg1, arg0, param1, param2]解决方法

Cause:org.apache.ibatis.binding.BindingException: Parameter ‘xxx’ not found. Available parameters are [arg1, arg0, param1, param2]解决方法

**Mapper.xml文件相关片段

    <select id="selectUserByParams" resultType="com.hnu.entity.User">
        SELECT * FROM USER WHERE name = #{name} and phone = #{phone}
    </select>

控制台输出的错误信息:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]

方法1.在***Mapper.java的接口文件中
将:

User selectUserByParams(String name,String phone);

修改为:

User selectUserByParams(@Param("name")String name, @Param("phone")String phone);

其中@Param(“xxx”)中的xxx与 ***Mapper.xml中#{xxx}中的xxx保持一致,为参数注解
(@Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应,一般在2=<参数数<=5时使用最佳。)

控制台成功输出:

User{id=3, name='王五', phone='1536537158'}

Process finished with exit code 0

方法2.修改 **Mapper.xml文件相关片段为:

    <select id="selectUserByParams" resultType="com.hnu.entity.User">
        SELECT * FROM USER WHERE name = #{arg0} and phone = #{arg1}
    </select>

控制台成功输出:

User{id=3, name='王五', phone='1536537158'}

Process finished with exit code 0
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值