mybatis的一堆多映射使用配置
自己仿站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的一堆多映射使用配置的更多相关文章
- 深入浅出Mybatis系列八-mapper映射文件配置之select、resultMap
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之inse ...
- 深入浅出Mybatis系列七-mapper映射文件配置之insert、update、delete
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(六)---objectFactory.p ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap good
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap[转]
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- MyBatis学习之路之configuration配置
1.首先讲解的是MyBatis核心配置文件configuration.xml的配置 一个完整的configuration.xml配置顺序如下: properties,settings,typeAlia ...
- 【转载】Mybatis多参数查询映射
转载地址:http://www.07net01.com/zhishi/402787.html 最近在做一个Mybatis的项目,由于是接触不久,虽然看了一下资料,但在实际开发中还是暴 露了很多问题,其 ...
- 【mybatis深度历险系列】mybatis中的高级映射一对一、一对多、多对多
学习hibernate的时候,小编已经接触多各种映射,mybatis中映射有到底是如何运转的,今天这篇博文,小编主要来简单的介绍一下mybatis中的高级映射,包括一对一.一对多.多对多,希望多有需要 ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc
在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件
随机推荐
- 常用的CSS小技巧
实际开发过程中会遇到一些需要用CSS小技巧处理的布局问题,现在分享几个个人工作中遇到的小问题和解决方案. 1.inline元素间的空白间隙 这里要介绍一个神器font-size:0. 如果你写了个列表 ...
- ajax学习摘抄笔记
2019独角兽企业重金招聘Python工程师标准>>> AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). A ...
- Codeforces 1291 Round #616 (Div. 2) C. Mind Control(超级详细)
C. Mind Control You and your n−1 friends have found an array of integers a1,a2,-,an. You have decide ...
- VMware15.5.0安装MacOS10.15.0系统 安装步骤(上)
VMware15.5.0安装MacOS10.15.0系统安装步骤(上)超详细! 说明: 本文是目前最新的安装和调配教程且MacOS10.15和10.16版本搭建方法相同,我也会在一些细节地方加上小技巧 ...
- file download hash mismatch
在linux中使用cmake时,遇到了"file download hash mismatch",同时status显示"unsupported protocol" ...
- MES系统介绍(一)
由于本人从事的行业主要为Mes行业,所以这里准备介绍一下Mes系统的基础概念和实际运用,并且以自己做过的一个实际案例(包括代码)来详细描述自己对Mes系统的认识,帮助小白扫盲,望大神勿喷. MES系统 ...
- 002_python的in,while else,格式化输出,逻辑运算符,int与bool转换,编码
数据 1.什么是数据? x=10,10是我们要存储的数据 2.为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3.数据类型 数字 字符串 列表 元组 字典 集合 ...
- C# 中 枚举Enum 一些转换的方法整理
工作中 经常遇到枚举 的一些转换 特别是获取枚举备注等 特地整理下 方法以后使用 public void TestMethod1() { TestEnumOne colorEnum = TestE ...
- PHP导出excel文件,第一步先实现PHP模板导出不带数据
今天继续研究PHP导出excel文件,把复杂的事情简单化,一步步实现功能,首先实现模板文件的导出,随后再实现写入数据后导出,最终实现功能,这是基本思路.中间可以加一步,先自己写入数据导出试试,随后再数 ...
- k近邻法(二)
上一篇文章讲了k近邻法,以及使用kd树构造数据结构,使得提高最近邻点搜索效率,但是这在数据点N 远大于 2^n 时可以有效的降低算法复杂度,n为数据点的维度,否则,由于需要向上回溯比较距离,使得实际效 ...