当Mybatis+sql遇到Expected one result (or null) to be returned by selectOne(), but found: 2时



Expected one result (or null) to be returned by selectOne(), but found: 2

Mybatis+sql出现以上问题时,说明sql只允许查询一个值 selectOne, 但是查询的结果有两条

这时候你就要去你的sql中找到sql语句


select
a.id as "id",
a.name as "name",
a.original_price as "original_price",
a.price as "price",
a.content as "content",
a.sales as "sales",
a.classify as "classify",
a.specification as "specification",
a.unit as "unit",
a.rxsp as "rxsp",
a.remark as "remark",
a.tjr as "tjr",
a.tjsj as "tjsj",
a.xgsj as "xgsj",
b.tpdz as "tpdz",
ifnull(c.sl,0) as "sl"
from mall_goods a
left join mall_goods_photo b on b.goods_id=a.id
left join mall_goods_cart c on a.id=c.goods_id and c.zh=#{zh}
where a.id=#{id}

and b.sfmr=#{sfmr}


and b.name=#{name}

group by a.id

and b.goods_id=#{goods_id}

大概位置在where a.id=#{id}的地方



解决方法:

  在where id=#{id}的下面 加一句    group by a.id  然后问题应该就不会报错了, 问题解决了.


Expected one result (or null) to be returned by selectOne(), but found: 2

你可能感兴趣的:(Throws,Common,Exceptions)