Mybatis xxxMapper.xml 三表关联,配置文件
VideoMapper.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="net.ybclass.online_ybclass.mapper.VideoMapper">
<resultMap id="videoDetailResultMap" type="Video">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="summary" jdbcType="VARCHAR" property="summary"/>
<result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
<result column="price" jdbcType="INTEGER" property="price"/>
<result column="point" jdbcType="DOUBLE" property="point"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<collection property="chapterList" ofType="Chapter">
<id column="chapter_id" jdbcType="INTEGER" property="id"/>
<result column="chapter_title" jdbcType="VARCHAR" property="title"/>
<result column="ordered" jdbcType="INTEGER" property="ordered"/>
<result column="chapter_create_time" jdbcType="TIMESTAMP" property="createTime"/>
<collection property="episodeList" ofType="Episode">
<id column="episode_id" jdbcType="INTEGER" property="id"/>
<result column="episode_title" jdbcType="VARCHAR" property="title"/>
<result column="num" jdbcType="INTEGER" property="num"/>
<result column="episode_ordered" jdbcType="INTEGER" property="ordered"/>
<result column="chapter_id" jdbcType="INTEGER" property="chapterId"/>
<result column="video_id" jdbcType="INTEGER" property="videoId"/>
<result column="play_url" jdbcType="VARCHAR" property="playUrl"/>
<result column="free" jdbcType="INTEGER" property="free"/>
<result column="play_create_time" jdbcType="TIMESTAMP" property="createTime"/>
</collection>
</collection>
</resultMap>
<select id="findDetailById" resultMap="videoDetailResultMap">
SELECT v.id,v.title,v.summary,v.cover_img,v.price,v.create_time,v.point,
c.id chapter_id,c.video_id,c.title chapter_title,c.ordered,c.create_time chapter_create_time,
e.id episode_id,e.num,e.chapter_id,e.video_id,e.title episode_title,e.ordered episode_ordered,e.play_url,e.free,e.create_time play_create_time
FROM video v
LEFT JOIN chapter c ON v.id=c.video_id
LEFT JOIN episode e ON c.id=e.chapter_id
WHERE v.id=#{video_id}
ORDER BY c.ordered,e.num ASC
</select>
</mapper>
Video.java
package net.ybclass.online_ybclass.domain; import java.util.Date;
import java.util.List; /**
* 视频对象
*/
public class Video {
private Integer id;
private String title;
private String summary;
private String coverImg;
private Integer price;
private Date createTime;
private Double point;
private List<Chapter> chapterList; public List<Chapter> getChapterList() {
return chapterList;
} public void setChapterList(List<Chapter> chapterList) {
this.chapterList = chapterList;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getSummary() {
return summary;
} public void setSummary(String summary) {
this.summary = summary;
} public String getConverImg() {
return coverImg;
} public void setConverImg(String converImg) {
this.coverImg = converImg;
} public Integer getPrice() {
return price;
} public void setPrice(Integer price) {
this.price = price;
} public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} public Double getPoint() {
return point;
} public void setPoint(Double point) {
this.point = point;
} @Override
public String toString() {
return "Video{" +
"id=" + id +
", title='" + title + '\'' +
", summary='" + summary + '\'' +
", converImg='" + coverImg + '\'' +
", price=" + price +
", createTime=" + createTime +
", point=" + point +
", chapterList=" + chapterList +
'}';
}
}
Chapter.java
package net.ybclass.online_ybclass.domain; import java.util.Date;
import java.util.List; /**
* 章
*/
public class Chapter {
private Integer id;
private Integer videoId;
private String title;
private Integer ordered;
private Date createTime;
private List<Episode> episodeList; public List<Episode> getEpisodeList() {
return episodeList;
} public void setEpisodeList(List<Episode> episodeList) {
this.episodeList = episodeList;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public Integer getVideoId() {
return videoId;
} public void setVideoId(Integer videoId) {
this.videoId = videoId;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public Integer getOrdered() {
return ordered;
} public void setOrdered(Integer ordered) {
this.ordered = ordered;
} public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} @Override
public String toString() {
return "Chapter{" +
"id=" + id +
", videoId=" + videoId +
", title='" + title + '\'' +
", ordered=" + ordered +
", createTime=" + createTime +
", episodeList=" + episodeList +
'}';
}
}
Episode.java
package net.ybclass.online_ybclass.domain; import java.util.Date;
import java.util.List; /**
* 集
*/
public class Episode {
private Integer id;
private String title;
private Integer num;
private Integer ordered;
private String playUrl;
private Integer chapterId;
private Integer free;
private Integer videoId;
private Date createTime;
public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public Integer getNum() {
return num;
} public void setNum(Integer num) {
this.num = num;
} public Integer getOrdered() {
return ordered;
} public void setOrdered(Integer ordered) {
this.ordered = ordered;
} public String getPlayUrl() {
return playUrl;
} public void setPlayUrl(String playUrl) {
this.playUrl = playUrl;
} public Integer getChapterId() {
return chapterId;
} public void setChapterId(Integer chapterId) {
this.chapterId = chapterId;
} public Integer getFree() {
return free;
} public void setFree(Integer free) {
this.free = free;
} public Integer getVideoId() {
return videoId;
} public void setVideoId(Integer videoId) {
this.videoId = videoId;
} public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} @Override
public String toString() {
return "Episode{" +
"id=" + id +
", title='" + title + '\'' +
", num=" + num +
", ordered=" + ordered +
", playUrl='" + playUrl + '\'' +
", chapterId=" + chapterId +
", free=" + free +
", videoId=" + videoId +
", createTime=" + createTime +
'}';
}
}
表结构
Mybatis xxxMapper.xml 三表关联,配置文件的更多相关文章
- 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错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
在学习Mybatis的时候,参考网上的教程进行简单demo的搭建,配置的没有问题,然后出现了下面的错误! Exception in thread "main" java.lang. ...
- Mybatis之Configuration初始化(配置文件.xml的解析)
源码解读第一步我觉着应该从Mybatis如何解析配置文件开始. 1.先不看跟Spring集成如何解析,先看从SqlSessionFactoryBuilder如果解析的. String resouce ...
- IDEA中写MyBatis的xml配置文件编译报错的坑
IDEA中写MyBatis的xml配置文件编译报错的坑 说明:用IDEA编译工具在项目中使用Mybatis框架,编写mybatis-config.xml和Mapper.xml配置文件时,编译项目出现错 ...
- gradle + mybatis 复制xml等配置文件到输出目录
问题 部署项目并启动项目后,使用mybatis时候,报一个错误:org.apache.ibatis.binding.BindingException: Invalid bound statement ...
- mybatis mapper.xml 配置文件问题(有的错误xml是不报的) 导致服务无法启动 。
转载自 开源编程 一舟mybatsi xml编译报错,tomcat启动一直循环,导致内存溢出,启动失败 mapper.xml怎么知道有没有编译错误,哪个位置有错误 这应该是mybatis的一个bug, ...
- clipse中mybatis的xml配置文件代码提示
编写mybatis的xml文件时,没有代码提示会很麻烦,是有解决办法的: 按下图打开 点击右上角的Add按钮,添加配置,配置如下,添加后点击OK: Location:http://mybatis.or ...
- 【Mybatis】MyBatis之表的关联查询(五)
本章介绍Mybatis之表的关联查询 一对一关联 查询员工信息以及员工的部门信息 1.准备表employee员工表,department部门表 CREATE TABLE `employee` ( `i ...
- Java基础-SSM之mybatis一对一外键关联
Java基础-SSM之mybatis一对一外键关联 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备测试环境(创建数据库表) 1>.创建husbandsfk和wife ...
- Mybatis的XML映射文件(四)
MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会立即发现省掉了将近 95% ...
随机推荐
- Oracle数据库下的DDL、DML、DQL、TCL、DCL
首发微信公众号:SQL数据库运维 原文链接:https://mp.weixin.qq.com/s?__biz=MzI1NTQyNzg3MQ==&mid=2247485212&idx=1 ...
- Composer 的下载与安装
一,Composer 的下载与安装 官网下载:https://getcomposer.org/download/ 打开 penssl的注释,在 D:\wamp\php7230\php.ini 文 ...
- django多表关联实战
定义模型类: from django.db import models from django.contrib.auth.models import User ''' ---------- Djang ...
- truffle 框架complie错误。
第一次使用trulle框架编译合约发现编译失败,原因是没有在truffle-config.js文件中加入编译器版本. module.exports = { // See <http://truf ...
- 使用 TestContainers 进行数据库集成测试
在软件开发过程中,集成测试是至关重要的一环.它确保不同组件之间的协作正常,并验证系统在整体上的功能和性能.然而,传统的集成测试往往需要依赖于外部资源,如数据库.消息队列等,这给测试环境的搭建和维护带来 ...
- Geatpy学习笔记1:官方案例
一.入门 1.求解器模式入门 案例 1 import geatpy as ea import numpy as np # 构建问题 r = 1 # 目标函数需要用到的额外数据 @ea.Problem. ...
- 安装centos7模板机[lvm版]
1. 安装centos 7模板机 准备好centos7的镜像 下载地址:http://mirrors.aliyun.com/centos/7/isos/x86_64/ 安装centos 自定义硬件: ...
- 《剑指offer - 题目2》
题目描述 请实现一个函数,将一个字符串中的每个空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 注意方 ...
- SQL必知必会(第5版) 读书笔记
适用范围 本书涵盖的DBMS一般来说,本书中所讲授的SQL可以应用到任何数据库管理系统(DBMS).但是,各种SQL实现不尽相同,本书介绍的SQL主要适用于以下系统(需要时会给出特殊说明和注释): ❑ ...
- c# 拖拽列表顺序 | 拖拽合并分组 | 移除分组功能
动图演示: 背景: 一开始做功能的时候没有增加排序的索引(sort-index),后来要求做拖拽排序功能:所以写了这个不需要初始排序就可以完成的拖拽功能:如果是table表格排序逻辑和这个相似,这里拿 ...