抛异常:Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2]

项目中使用springboot+mybatis 进行数据查询的时候,出现了这个bug
我的dao是这样写的

    List<FhxInternalCompanyCeded> selectCompanyCededToView( String treatyid, String provincecomcode);

mapper是这么写的:

	<select id="selectCompanyCededToView"  resultMap="BaseResultMap">
		select *
		<include refid="Base_Column_List"/>
		from FhxInternalCompanyCeded
		where 1=1
		<if test="treatyid != null and treatyid != ''">
			AND treatyid = #{treatyid}
		</if>

		<if test="provincecomcode != null and provincecomcode != ''">
			AND provincecomcode = #{provincecomcode}
		</if>
	</select>

查询的时候报
Parameter ‘treatyid’ not found. Available parameters are [arg1, arg0, param1, param2]
第一种情况,也是新手经常遇到的情况就是,方法名不对,
一般都是英文少字母或者大小写问题
如果不是参数名不对,有以下两种解决办法
方法一:

按照网上的说法,把参数改为arg1,arg2

	<select id="selectCompanyCededToView"  resultMap="BaseResultMap">
		select *
		<include refid="Base_Column_List"/>
		from FhxInternalCompanyCeded
		where 1=1
		<if test="treatyid != null and treatyid != ''">
			AND treatyid = #{arg1} **//更改处**
		</if>

		<if test="provincecomcode != null and provincecomcode != ''">
			AND provincecomcode = #{arg2}/**/更改处**
	
		</if>
	</select>

仍然报错
第二种:
参数前面添加@Param(“参数名”),进行参数定义,代码如下

    List<FhxInternalCompanyCeded> selectCompanyCededToView(@Param("treatyid") String treatyid,@Param("provincecomcode") String provincecomcode);

这里很可能会因为没有引入包,导致@Param报错
别忘了导入@Param的包

import org.apache.ibatis.annotations.Param;

这样就大功告成了
本菜鸟自己创建的交流群,欢迎大佬和java学习者加入扣扣群:344635699

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值