mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map
用mybaits 写一个关联查询 查询商品表关联商品规格表,并查询规格表中的数量、价格等,为了sql重用性,利用 association 节点 查询 结果并赋值报错
商品表的mapper文件为GooodsMapper.xml 规格表的mapper 文件为GoodsSpecificationsMapper.xml
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map
GooodsMapper.xml的内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chengpin.mapper.GoodsMapper">
<insert id="save" parameterType="Goods">
insert into t_goods
(no,category,title,selling_point,cover_picture,unit_price,freight_template,shop_category,
service_commitment,return_commitment,guarantee_service,
provide_invoice,is_shelf,shelf_time,state,purchasing_place,release_time,publisher)
values
(GOODS_SEQUENCE.nextval,#{category},#{title},#{selling_point},#{cover_picture},#{unit_price},
#{freight_template},#{shop_category},#{service_commitment},
#{return_commitment},#{guarantee_service},#{provide_invoice},#{is_shelf},#{shelf_time},#{state},#{purchasing_place},
#{release_time},#{publisher})
<selectKey keyProperty="no" order="AFTER" resultType="java.lang.String">
select GOODS_SEQUENCE.CURRVAL from DUAL
</selectKey>
</insert> <select id="selectGoodsInfoTotalSize" parameterType="Map" resultType="Integer">
select
count(*)
from
T_GOODS
WHERE
category = #{categoryno}
</select> <select id="selectGoodsInfo" parameterType="Map" resultType="Map">
select
goodsno,goodstitle,goodsprice,goodsimgurl
from (
select
g.cover_picture goodsimgurl,
g.no goodsno,
g.title goodstitle,
g.unit_price goodsprice,
rownum num
from T_GOODS g
where g.category = #{categoryno}
and rownum <= #{endPage}
order by
<if test="@com.chengpin.core.util.StringUtils@isNotEmpty(priceUp)">
g.unit_price desc,
</if>
<if test="@com.chengpin.core.util.StringUtils@isNotEmpty(priceDown)">
g.unit_price asc,
</if>
<if test="@com.chengpin.core.util.StringUtils@isNotEmpty(last)">
g.release_time desc,
</if>
g.no desc
)
where
num >= #{startPage}
</select> <!-- 根据用户编号和商品状态查询商品信息 -->
<select id="selectGoodsByState" resultType="Goods">
select * from t_goods where publisher=#{user_no} and state=#{state}
</select>
<select id="selectGoodsDetailsByGoodsNo" parameterType="Map" resultType="Map">
select
g.no "no",
g.selling_point "sellpoint",
g.title "title",
g.unit_price "original_price",
gs.price "present_price",
gs.quantity "quantity",
tgi.content "goodscontent"
from
t_Goods g
left join
T_GOODS_SPECIFICATIONS gs
on g.no = gs.goods_no
left join
T_GOODS_INTRODUCTION tgi
on tgi.goods_no = g.no
where g.no = #{goodsno}
<if test="@com.chengpin.core.util.StringUtils@isNotEmpty(goodscolor)">
and gs.color_value = #{goodscolor}
</if>
and rownum = 1
</select> <select id="selectGoodsInfoAndTotalPriceByUserNoState" resultMap="goodsInfoAndTotalPrice">
select g.no goods_no,g.title,g.release_time,g.shelf_time,g.off_shelf,g.cover_picture
from t_goods g where g.publisher = #{user_no} and g.state=#{state}
group by g.no,g.title,g.release_time,g.shelf_time,g.off_shelf,g.cover_picture
order by g.release_time desc
</select> <resultMap type="Goods" id="goodsInfoAndTotalPrice">
<id property="no" column="no" />
<result property="title" column="title"/>
<result property="release_time" column="release_time"/>
<result property="shelf_time" column="shelf_time"/>
<result property="off_shelf" column="off_shelf"/>
<association property="total" column="goods_no" javaType="Integer"
select="mybatis.mapper.GoodsSpecificationsMapper.selectGoodsTotalByGoodsNo"/>
<association property="lowest_price" column="goods_no" javaType="Double"
select="com.chengpin.mapper.GoodsSpecificationsMapper.selectLowestPrice"/>
</resultMap>
</mapper>
GoodsSpecificationsMapper.xml 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chengpin.mapper.GoodsSpecificationsMapper">
<!-- 保存商品规格方法 -->
<insert id="save">
insert into t_goods_specifications
(no,goods_no,color_value,size_value,quantity,price)
values
(goods_specifications_sequence.nextval,#{goods_no},
#{specifications.color_value},#{specifications.size_value},#{specifications.quantity},#{specifications.price})
</insert> <!-- 根据商品编号查询商品总数 -->
<select id="selectGoodsTotalByGoodsNo" parameterType="String" resultType="Integer">
select sum(quantity) total from t_goods_specifications where goods_no = #{goods_no}
</select> <!-- 根据商品编号查询商品最低价 -->
<select id="selectLowestPrice" parameterType="String" resultType="Double">
select min(price) from t_goods_specifications where goods_no = #{goods_no}
</select>
</mapper>
最后发现错误来源于此
<association property="total" column="goods_no" javaType="Integer"
select="mybatis.mapper.GoodsSpecificationsMapper.selectGoodsTotalByGoodsNo"/>
原来是我吧select 中 对GoodsSpecificationsMapper.xml 文件的 select 查询调用的 空间写错了
我写的是src 路径 并不是 写的 mapper 的namespace 空间位置 把值改如下 便正确了
<association property="total" column="goods_no" javaType="Integer"
select="com.chengpin.mapper.GoodsSpecificationsMapper.selectGoodsTotalByGoodsNo"/>
mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map的更多相关文章
- 搭建Mybatis 出现 Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mapper.BatchCustomer.findBatchCustomerOneToOne
Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection doe ...
- java - mybatis:java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for
当遇见java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for 错误的时候 ...
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.bjsxt.mapper.PeopleMapper
报错信息: Type Exception Report Description The server encountered an unexpected condition that prevente ...
- Mybatis 报错 java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Inte
like ‘%java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.la ...
- mybatis报错: java.lang.IllegalArgumentException invalid comparison: java.util.Date and java.lang.String
原因是在使用<if> 进行条件判断时, 将datetime类型的字段与 ' ' 进行了判断,导致的错误 解决, 只使用 <if test="createTime != n ...
- nested exception is java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoSupport': ...
- Caused by: java.lang.IllegalArgumentException: Parameter Maps collection does not contain value for com.bj186.crm.mapper.UserMapper.Integer
在使用SSM整合myBatis的过程中遇到了这个问题. 问题的原因: 把parameterType错误的写成了parameterMap 解决办法: 将parameterMap修改为parameterT ...
- mybatis异常:Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for。。。。。。
框架环境:ssm 昨天下午技术经理更新了下表结构,多加了一个字段. 之后我根据新的mapper.xml文件写了增删改查的操作.重新启动之后不是这个错就是那个错,一大堆错误,头疼. 像类似于NoSuch ...
- Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.st.mapper.UserMapper.userBaseMap
mybatis出现此异常,可能是因为 ***Mapper.xml 文件中存在重名对象,一不小心重复启动了mybatis的逆向工程. 以为会覆盖掉以前生成的,没想到是新生成的和之前生成的重复了 解决:把 ...
随机推荐
- CentOS最小化安装后启用无线连接网络
想要链接无线就需要无线工具包. yum install -y wireless-tools安装完成之后就有 iwconfig,iwlist,iw等命令行工具了. 首先启动无线网卡,记得开启无线开关, ...
- Java变量和对象的作用域
大多数程序设计语言都提供了"作用域"(Scope)的概念. 对于在作用域里定义的名字,作用域同时决定了它的"可见性"以及"存在时间".在C, ...
- Zookeeper-3.4.9 集群搭建
这里用了三台主机,系统为CentOS7 1.修改hosts #vim /etc/hosts 172.50.0.31 node1 172.50.0.34 node2 172.50.0.37 node3 ...
- PAT乙级练习1001
1001. 害死人不偿命的(3n+1)猜想 (15) 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去, ...
- XJOI1424解压字符串
解压字符串 给你一个字符串S,S是已经被加密过的字符串.现在要求你把字符串S还原.字符串S可能会出现这样的格式:k(q),它表示字符串q重复了k次,其中q是0个或多个字符,而k是一个数字,范围是0至9 ...
- 老李分享:adb发送的指令都有哪些
老李分享:adb发送的指令都有哪些 这两天在poptest上课的时候,我们邀请了业内技术牛人为我们的学员讲解手机自动化方面的知识,每天大家都很踊跃,要学习到晚上11点多才能,有的学员跟我说都累傻了 ...
- Java Level 2 学习的八大名著
Java Level 2 学习的八大名著 前段时间有几天难得的假期,于是把自己认为Java技术栈中的精华总结了一下,但是一直没有时间写下来,今天终于得空希望本文可以对大家有所启发.通过多个实际项目的沉 ...
- linux sort命令详解(转)
sort命令是帮我们依据不同的数据类型进行排序,其语法及常用参数格式: sort [-bcfMnrtk][源文件][-o 输出文件] 补充说明:sort可针对文本文件的内容,以行为单位来排序. 参 数 ...
- 开始使用ansible
ansible是一个设计巧妙,功能强大,安全,使用简单的IT自动化运维工具.它可以实现统一配置管理,持续部署,流程编排等. 目前控制主机必须是linux,被控制主机可以是linux,类UNIX和win ...
- hexo工具介绍及使用方法
Hexo is a fast, simple & powerful blog framework 安装方法:npm install hexo-cli -g; require:node.js g ...