项目中使用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