用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 &lt;= #{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 &gt;= #{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的更多相关文章

  1. 搭建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 ...

  2. java - mybatis:java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for

    当遇见java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for 错误的时候 ...

  3. 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 ...

  4. 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 ...

  5. mybatis报错: java.lang.IllegalArgumentException invalid comparison: java.util.Date and java.lang.String

    原因是在使用<if> 进行条件判断时, 将datetime类型的字段与 ' ' 进行了判断,导致的错误 解决, 只使用  <if test="createTime != n ...

  6. 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': ...

  7. 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 ...

  8. mybatis异常:Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for。。。。。。

    框架环境:ssm 昨天下午技术经理更新了下表结构,多加了一个字段. 之后我根据新的mapper.xml文件写了增删改查的操作.重新启动之后不是这个错就是那个错,一大堆错误,头疼. 像类似于NoSuch ...

  9. Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.st.mapper.UserMapper.userBaseMap

    mybatis出现此异常,可能是因为 ***Mapper.xml 文件中存在重名对象,一不小心重复启动了mybatis的逆向工程. 以为会覆盖掉以前生成的,没想到是新生成的和之前生成的重复了 解决:把 ...

随机推荐

  1. 用webstorm自动编译less产出css和sourcemap

    css产出sourcemap有什么用呢,可能大家要问这个问题了. 请移步这里 https://developers.google.com/chrome-developer-tools/docs/css ...

  2. php写留言板

    简单的PHP留言板制作 做基础的留言板功能  需要三张表: 员工表,留言表,好友表 首先造一个登入页面: <form action="drcl.php" method=&qu ...

  3. 开源 & 免费使用 & 打包下载自行部署 :升讯威 周报系统

    这个周报系统大约写于2015年,缘起当时所带的开发团队需要逐步建立或完善一些项目管理方法. 在调研了网上的诸多项目管理或周报/日报管理系统之后,并没有找到符合当时情况的系统,这里最大的问题不是网上既有 ...

  4. 储存过程嵌套临时表同名引发的BUG?

    临时表使用:存储过程嵌套时,均创建了相同名称的临时表. create procedure SP_A ( @i int output )asbegin create table #t ( ta int ...

  5. dellR720重启找不到启动引导项,手动选择也无用。

    机器重启后显示 no boot device available.(如下图)检查bios中设置也是没问题的,因为装完系统后根本没动过什么.F11手动选择启动项也还是会跳到这里来. 这台机子做的Raid ...

  6. iOS最好用的引导页

    最近项目结束的时候又要改引导页,之前写的启动页改起来太麻烦了,所以就直接封装一个,功能可能还不是很完善,但是感觉用起来也比较方便,在这里和大家分享一下. 这是github的下载地址:https://g ...

  7. vagrant up 失败解决办法

    前几天在自己电脑搭建vagrant环境报错:"There was an error while executing `VBoxManage`, a CLI used by Vagrant f ...

  8. $_GET

    POST GET ,是提交表单的两种方式,GET传值就用$_GET获取,POST提交表单就用$_POSTpost与get的区别是一个在地址栏显示参数,另一个不显示 如果地址是这样:http://zhi ...

  9. python作业设计:多级菜单,并可依次进入各级子菜单

    '''作业三:多级菜单 三级菜单 可依次选择进入各子菜单 所需新知识点:列表.字典 ''' data = { "北京":{ "昌平":{ "沙河&qu ...

  10. 使用HTTP的同步方式还是异步方式?

    同步与异步 同步:提交请求->等待服务器处理->处理完毕返回 这个期间客户端浏览器不能干任何事 异步: 请求通过事件触发->服务器处理(这是浏览器仍然可以作其他事情)->处理完 ...