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% ...
随机推荐
- EclEmma的介绍、安装与使用
p{line-height: 200%} 1. EclEmma的介绍 EclEmma是一个开源的软件测试工具,可以在编码过程中查看代码调用情况.也可以检测单覆盖率. 2. Eclipse下 ...
- 老鼠跑猫叫主人惊醒c++观察者模式实现
这个题目算是比较经典的观察者模式了,老鼠作为一个Subject,主动发出跑的动作,紧跟着猫由于老鼠的跑而发出叫声,主人也被惊醒,在这里猫跟主人都是被动的,是观察者角色,代码实现如下: class CS ...
- [Z] 计算机类会议期刊根据引用数排名
一位cornell的教授做的计算机类期刊会议依据Microsoft Research引用数的排名 link:http://www.cs.cornell.edu/andru/csconf.html Th ...
- 关于STM8的用户数据空间读写问题
情况是这样的,我的程序里有一个参数,数值不超过1000,我要保存到EEPROM中,那就要分两个字节存放.我用下面的方式保存是正常的: BASE = 0x4000; param = 999; eepro ...
- ASP - MSXML2.ServerXMLHTTP & HTTPS & 证书过期 — msxml3.dll '80072f05'
Error: msxml3.dll '80072f05' The date in the certificate is invalid or has expired Dim xmlhttp Set ...
- ubuntu14.04服务版/etc/init.d/smbd restart无效的解决方法
刚装的ubuntu14.04配置完smbd发现service或者/etc/init.d/smbd restart都不显示任何输出,也没起作用 echo $?输出1,查看脚本发现 if init_is_ ...
- ICMP type code 对应表(转)
ICMP类型 TYPE CODE Description Query Error 0 0 Echo Reply——回显应答(Ping应答) x 3 0 Network Unreachable——网 ...
- 实时流式计算框架Storm 0.9.0发布通知(中文版)
Storm0.9.0发布通知中文翻译版(2013/12/10 by 富士通邵贤军 有错误一定告诉我 shaoxianjun@hotmail.com^_^) 我们很高兴宣布Storm 0.9.0已经成功 ...
- centos 7 卸载 mariadb 的正确命令
#列出所有被安装的rpm package rpm -qa | grep mariadb #卸载 rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64 错误:依赖检测失败: ...
- .NET面试必备(整理)
1.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问.public : 公共成员,完全公开,没有 ...