自己仿站jeep官网在制作商城时,商品详情页面需要带着一个商品的信息,商品的配置,配置对应的颜色,商品的图片   如图

首先设计业务bean

一辆车的信息

业务一对多的大业务bean,继承Car.java

几个list的类型不做赘述,本博客主要讲映射

对应的marrp.xml中设置

创建

<resultMap type="cn.jeep.CarBean.detailsCar" id="oneCar">
<id column="carid" jdbcType="VARCHAR" property="carid" />
<result column="carimg" jdbcType="VARCHAR" property="carimg" />
<result column="carname" jdbcType="VARCHAR" property="carname" />
<result column="cartext" jdbcType="VARCHAR" property="cartext" />
<result column="carzt" jdbcType="INTEGER" property="carzt" />
<!-- 多表 -->
<!-- 配置信息 -->
<collection property="peizhi" ofType="cn.jeep.CarBean.carPeizhi" javaType="java.util.ArrayList" column="carid" select="selectPerizhi">
<id column="zys_carpeizhi_id" jdbcType="VARCHAR" property="carid" />
<result column="pid" jdbcType="VARCHAR" property="pid" />
<result column="pname" jdbcType="VARCHAR" property="pname" />
<result column="pzt" jdbcType="INTEGER" property="pzt" />
</collection>
<!-- 配置图片 -->
<collection property="liimg" ofType="cn.jeep.CarBean.carImg" javaType="java.util.ArrayList" column="carid" select="selectPimg">
<id column="carid" jdbcType="VARCHAR" property="carid" />
<result column="carimg" jdbcType="VARCHAR" property="carimg" />
</collection>
<!-- 详细配置图片 -->
<collection property="liximg" ofType="cn.jeep.CarBean.xCarImg" javaType="java.util.ArrayList" column="carid" select="selectPximg">
<id column="xcarid" jdbcType="VARCHAR" property="xcarid" />
<result column="xcarimg" jdbcType="VARCHAR" property="xcarimg" />
</collection>
</resultMap>
<!-- 多表 -->
<!-- 配置信息 -->
<resultMap id="perizhiMap" type="cn.jeep.CarBean.carPeizhi">
<id column="zys_carpeizhi_id" jdbcType="VARCHAR" property="carid" />
<result column="pid" jdbcType="VARCHAR" property="pid" />
<result column="pname" jdbcType="VARCHAR" property="pname" />
<result column="pzt" jdbcType="INTEGER" property="pzt" />
</resultMap>
<!-- 配置图片 -->
<resultMap id="carImg" type="cn.jeep.CarBean.carImg">
<id column="carid" jdbcType="VARCHAR" property="carid" />
<result column="carimg" jdbcType="VARCHAR" property="carimg" />
</resultMap>
<!-- 详细配置图片 -->
<resultMap id="xcarImg" type="cn.jeep.CarBean.xCarImg">
<id column="xcarid" jdbcType="VARCHAR" property="xcarid" />
<result column="xcarimg" jdbcType="VARCHAR" property="xcarimg" />
</resultMap>
<!-- 第一个配置颜色 -->
<resultMap id="selectPcolor" type="cn.jeep.CarBean.peizhiColor">
<id column="colorid" jdbcType="VARCHAR" property="colorid" />
<result column="colorname" jdbcType="VARCHAR" property="colorname" />
</resultMap>

多次尝试,常规使用的一对多映射不需要写每个bean独立的    resultMap   但是映射过程中打断点发现所有list只能取到每个的第一行数据。

      <!-- 封装大型产品详情页的业务bean -->

      <!-- 测试多字段映射===================================================  -->
<select id="detailsCars" resultMap="oneCar">
SELECT
zys_cark.`carid`,
zys_cark.`carimg`,
zys_cark.`carname`,
zys_cark.`cartext`,
zys_cark.`carzt`
from zys_cark
WHERE zys_cark.`carid`=#{carid}
</select>
<!-- 配置图片 -->
<select id="selectPerizhi" resultMap="perizhiMap">
select * from zys_carpeizhi where zys_carpeizhi.`carid` =#{carid}
</select>
<!-- 详细配置 -->
<select id="selectPimg" resultMap="carImg">
SELECT * FROM zys_carimg WHERE carid=#{#carid}
</select>
<!-- 详细图片 -->
<select id="selectPximg" resultMap="xcarImg">
select * from zys_xcarimg where xcarid=#{carid}
</select> <!-- 查一个汽车配置的颜色 -->
<select id="selectOneColor" resultMap="selectPcolor">
SELECT zys_pcolor.`colorid`,zys_color.`colorname`,zys_pcolor.`czt` FROM zys_carpeizhi JOIN zys_pcolor JOIN zys_color
ON zys_carpeizhi.`pid`=zys_pcolor.`pid` AND zys_color.`colorid`=zys_pcolor.`colorid` WHERE zys_carpeizhi.`pid`=#{pid}
</select>

mybatis的一堆多映射使用配置的更多相关文章

  1. 深入浅出Mybatis系列八-mapper映射文件配置之select、resultMap

    注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之inse ...

  2. 深入浅出Mybatis系列七-mapper映射文件配置之insert、update、delete

    注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(六)---objectFactory.p ...

  3. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap

    上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...

  4. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap good

    上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...

  5. 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap[转]

    上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...

  6. MyBatis学习之路之configuration配置

    1.首先讲解的是MyBatis核心配置文件configuration.xml的配置 一个完整的configuration.xml配置顺序如下: properties,settings,typeAlia ...

  7. 【转载】Mybatis多参数查询映射

    转载地址:http://www.07net01.com/zhishi/402787.html 最近在做一个Mybatis的项目,由于是接触不久,虽然看了一下资料,但在实际开发中还是暴 露了很多问题,其 ...

  8. 【mybatis深度历险系列】mybatis中的高级映射一对一、一对多、多对多

    学习hibernate的时候,小编已经接触多各种映射,mybatis中映射有到底是如何运转的,今天这篇博文,小编主要来简单的介绍一下mybatis中的高级映射,包括一对一.一对多.多对多,希望多有需要 ...

  9. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc

    在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件

随机推荐

  1. Spring PropertyPlaceholderConfigurer类载入外部配置

    2019独角兽企业重金招聘Python工程师标准>>> 通常在Spring项目中如果用到配置文件时,常常会使用org.springframework.beans.factory.co ...

  2. C语言编程入门题目--No.8

    题目:输出9*9口诀. 1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列. 2.程序源代码: #include "stdio.h" main() { int i,j,re ...

  3. Codeforces Round #530 (Div. 1) 1098A Sum in the tree

    A. Sum in the tree Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root ha ...

  4. salesforce零基础学习(九十七)Event / Task 针对WhoId的浅谈

    我们在Sales Cloud中经常会创建顾客,如果针对TO C业务,会启用个人顾客,比如针对车企行业,有一些场景是需要卖给个人的,而不只是企业采购.当通过打电话或者其他的场景有潜在客户并且转换成客户以 ...

  5. Bootstrap Table 3 官方文档

    备查 Bootstrap Table 3 官方文档 示例

  6. 【2020Java最新学习路线】写了很久,这是一份最适合普通大众、科班、非科班的路线

    点赞再看,养成习惯,微信搜索[三太子敖丙]关注这个互联网苟且偷生的工具人. 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试完整考点.资料以及我的 ...

  7. zabbix-agent客户端安装与配置

    zabbix-agent客户端安装与配置 下载abbix-agent客户端源码软件包 解压agent源码包,并且切换到解压目录. [root@localhost ~]# tar -zxf zabbix ...

  8. Mysql 常用函数(19)- mod 函数

    Mysql常用函数的汇总,可看下面系列文章 https://www.cnblogs.com/poloyy/category/1765164.html mod 的作用 求余数,和%一样 mod的语法格式 ...

  9. HBase 安装snappy压缩软件以及相关编码配置

    HBase 安装snappy压缩软件以及相关编码配置 前言 ​ 在使用HBase过程中因为数据存储冗余.备份数等相关问题占用过多的磁盘空间,以及在入库过程中为了增加吞吐量所以会采用相关的压缩算法来压缩 ...

  10. 使用github作为maven仓库存放发布自己的jar包依赖 实现多个项目公共部分代码的集中,避免团队中多个项目之间代码的复制粘贴

    使用github作为maven仓库存放发布自己的jar包依赖 实现多个项目公共部分代码的集中,避免团队中多个项目之间代码的复制粘贴. 1.首先在本地maven位置的配置文件setting.xml(没有 ...