博客转载自链接:https://blog.csdn.net/ILV_XJ/article/details/80761726
在使用mybatis开发的时候,有时候需要传入多个参数进行查询,当传入多个参数时,不会处理会出现下面异常:
出现上面异常的原因是*mapper.xml映射没有得到传入的参数,这个时候需要在DAO变化传参,下面对比一下错误的和正确的传参方式:
有错的:
public List<EquipmentUser> findEquipmentUserInfoBySystemUserId(Integer userId, String equipmentType);
要使用@Param(“userId”)注解进行传参,才能让*mapper.xml文件得到参数,正确的写法如下:
public List<EquipmentUser> findEquipmentUserInfoBySystemUserId(@Param("userId")Integer userId, @Param("equipmentType")String equipmentType);
注意:有的开发者即使使用了@Param注解,还是会报这个异常,原因是在导包的时候,导入的是spring的@Param的注解包,在这里我们需要导入mybatis的@Param注解包,也就是org.apache.ibatis.annotations.Param;这个包