mybatis mapper association collection
1.Question Description:
sometimes, POJO bean contains another bean or collection as property,
it's suitable for select data from more than one table.
2. Solution:
2.1 mybatis mapper file , for example:
<mapper namespace="cn.net.syl.dao.ProductsMapper" >
<resultMap id="BaseResultMap" type="cn.net.syl.model.Products" >
<id column="product_id" property="productId" jdbcType="BIGINT" />
<result column="product_name" property="productName" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="descript" property="descript" jdbcType="VARCHAR" />
<result column="price" property="price" jdbcType="DOUBLE" />
......
</resultMap>
.....
<resultMap type="cn.net.syl.model.Products" id="BigResultMap" extends="BaseResultMap">
<association property="prodExt" javaType="cn.net.syl.model.ProductsExt">
<id column="product_ext_id" property="productExtId" jdbcType="BIGINT" />
<result column="product_id" property="productId" jdbcType="BIGINT" />
....
</association>
<collection property="prodPropImgList" ofType="cn.net.syl.model.ProductsPreviewImages">
<id column="prev_id" property="prevId" jdbcType="BIGINT" />
<result column="product_id" property="productId" jdbcType="BIGINT" />
..........
</collection>
</resultMap>
<select id="getProductInfo" resultMap="BigResultMap" parameterType="java.lang.Long">
select
a.*, b.detail_descript,
c.image_url,
c.product_id,
c.property_id,
c.value_id,
d.value_name
FROM
syl_products a,
syl_products_ext b,
syl_products_preview_images c,
syl_property_values d
where a.product_id = b.product_id
and a.product_id = c.product_id
and c.value_id = d.value_id
and a.product_id = #{productId}
</select>
</mapper>
2.2 POJO bean , for example:
public class Products {
private String idStr;
private Long productId;
private String productName;
............
//add field for sql
private ProductsExt prodExt;
//add field for sql
List<ProductsPreviewImages> prodPropImgList;
//add field for sql
private List<ProductPropertyEntity> baseProdPropList;
//getter and setter method
....
}
mybatis mapper association collection的更多相关文章
- mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mybatis.map
用mybaits 写一个关联查询 查询商品表关联商品规格表,并查询规格表中的数量.价格等,为了sql重用性,利用 association 节点 查询 结果并赋值报错 商品表的mapper文件为Gooo ...
- 解决 Mybatis 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminat
在配置 mybatis mapper.xml文件时, 一不小心就会报如下类似的异常: Caused by: org.springframework.beans.factory.BeanCreation ...
- Mybatis中的collection、association来处理结果映射
前不久的项目时间紧张,为了尽快完成原型开发,写了一段效率相当低的代码. 最近几天闲下来,主动把之前的代码优化了一下:) 标签:Java.Mybatis.MySQL 概况:本地系统从另外一个系统得到 ...
- mybatis项目启动报错 The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
启动项目报错 2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initi ...
- association ,collection
mybatis 出现这个错误Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2 ...
- MyBatis——Mapper XML 文件
Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会 ...
- MyBatis Mapper XML 详解
MyBatis Mapper XML 详解 MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方.对于所有的力量,SQL 映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JD ...
- mybatis Result Maps collection already contains value for com.ebways.dictionary.dao.impl.PtInfoDaoImpl.beanMap
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- mybatis Mapper XML 文件
MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会立即发现省掉了将近 95% ...
随机推荐
- fflua更新-增加对引用的支持
简介: fflua 发布了有段时间了,很多网友都用了,并且提供了一些很好的反馈.其中一个就是c++接口注册到lua中时,对引用的支持.这样使用起来更加方便. 原有方式: fflua 中注册c++的类用 ...
- sql优化之(DMV)
原文地址:http://technet.microsoft.com/zh-cn/library/bb838723.aspx Microsoft SQL Server 2005 提供了一些工具来监控数据 ...
- asp.net首页设置
在web.config中设置首页 <configuration> <system.web> <compilation debug="true" tar ...
- Eclipse中如何修改SVN的地址
在SVN服务端的IP更改后,客户端SVN的连接地址可以在Eclipse中进行修改,方法如下: 首先:在Eclipse中选择Windows-> Show View->others 就会出现[ ...
- 关于STM8的用户数据空间读写问题
情况是这样的,我的程序里有一个参数,数值不超过1000,我要保存到EEPROM中,那就要分两个字节存放.我用下面的方式保存是正常的: BASE = 0x4000; param = 999; eepro ...
- LeetCode: 221_Maximal Square | 二维0-1矩阵中计算包含1的最大正方形的面积 | Medium
题目: Given a 2D binary matrix filled with 's and return its area. For example, given the following ma ...
- EDM营销之双十一最新实战营销指南汇总
双十一虽已进入第八个年头,但其影响力只增不减,倒计时期间商家们都已火力全开.再结合全社会消费升级的大背景,如何才能在激烈竞争中杀出一条血路呢? 本次Focussend基于实战操作,以短信营销.邮件营销 ...
- 如何复制DataRow(dataTabel中的行)
由于需要对dataTabel中的行进行上移和下移操作: row 1 行号0 row2 行号1 row3 行号2 例如将row3上移一行,即row2和row3对调位置. ...
- Ext.grid.GridPanel属性及方法等
1.Ext.grid.GridPanel主要配置项:store:表格的数据集columns:表格列模式的配置数组,可自动创建ColumnModel列模式autoExpandColumn:自动充满表格未 ...
- ArcGIS“一个或多个ActiveX控件无法显示...”问题的解决方案
ArcMap启动时的一个警告信息“一个或多个ActiveX控件无法显示...”,如图 出现这种情况,有可能的原因是IE浏览器的安全选项设置被修改了.比如被手动修改过,或者被第三方系统杀毒优化软件修改了 ...