测试问题
来源:6-5 店铺列表展示之Dao层的实现
慕沐8221787
2020-04-13
测试queryShopCount方法出现一个很奇怪的现象,如果去掉方法中的参数注解@Pram(“shopCondition”),如下第二行的写法:
int queryShopCount(@Param(“shopCondition”) Shop shopCondition);
int queryShopCount(Shop shopCondition);
测试运行就出错,错误提示如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘shopCondition’ in ‘class com.imooc.o2o.entity.Shop’
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘shopCondition’ in ‘class com.imooc.o2o.entity.Shop’
xml文件代码如下:
select count(1)
from tb_shop s
left join tb_area a
on a.area_id=s.area_id
left join tb_shop_category c
on s.shop_category_id=c.shop_category_id
and s.shop_name like %+#{shopCondition.shopName}+%
and s.shop_category_id=#{shopCondition.shopCategory.shopCategoryId}
and s.area_id=#{shopCondition.area.areaId}
and s.enable_status=#{shopCondition.enableStatus}
and s.owner_id=#{shopCondition.owner.userId}
请问这是什么原因呢?
1回答
-
你如果没有指明参数值是啥,mybatis就会按照它自己的理解,借助ASM去映射名字,然后去查找类型,就会报这样的异常,上面说的是源码的实现,感兴趣可以了解一下,所以这才是@Param存在的意义
042020-04-15
相似问题