测试问题

来源: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回答

翔仔

2020-04-14

你如果没有指明参数值是啥,mybatis就会按照它自己的理解,借助ASM去映射名字,然后去查找类型,就会报这样的异常,上面说的是源码的实现,感兴趣可以了解一下,所以这才是@Param存在的意义

0
4
翔仔
回复
慕沐8221787
mybatis文档是怎么说的呢
2020-04-15
共4条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程