错误信息表明在MyBatis中存在参数绑定的问题,具体为找不到名为'category'的参数。MyBatis无法找到'category'参数,并列出了可用的参数为'arg1'、'arg0'、'param1'和'param2'。mybatis的dao层函数参数列表有多个参数,直接传到mapper.xml匹配报错!
解决一
使用#{arg0}和#{arg1}来告诉mybatis,当前变量使用哪个参数的值
<select id="query" resultType="int">
select count(1) as count from itcaststore.products
<where>
<if test="category != null">
category like concat('%',#{arg0},'%')
</if>
<if test="name != null">
and name like concat('%',#{arg1},'%')
</if>
</where>
</select>
解决二
使用注解@Param
public int queryProductsCount(@Param("name") String name, @Param("category")String category);
解决三
HashMap类型作为传入类型(不修改mapper.xml)
public int queryProductsCount1(Map<String,String> map);