MyBatis多表查询

手敲Mybatis(七)-细化xml语句解析和构建 为什么这一章节要细分之前的解析xml处理逻辑,原因是违反了单一原则设计,职责并不明确,将Sql语句、参数、返回值等等一切都进行解析,那么这种的需要拆开,为了后面可维护可扩展,例如Mapper级别的有mapper解析,Sql语句有Sql语句的解析,因为Sql也是脚本,需要对脚本进行动态处理,也会延伸一些脚本类来处理对应语句图一,全部职责混到一个类里一个方法里。 阅读详情

目录

1.一对一查询

1.1一对一查询的模型

2.一对多查询

2.1一对多查询的模型

3.多对多查询

3.1多对多查询的模型

4.知识小结


1.一对一查询

1.1一对一查询的模型

用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户,一对一查询的需求:查询一个订单,与此同时查询出该订单所属的用户。

 

<?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="com.caoyan.mapper.OrderMapper">
  <resultMap id="orderMap" type="order">
      <!-- 手动指定字段与实体属性的映射关系
        column:数据表的字段名称
        property:实体的属性名称
     -->
     <id column="oid" property="id"/>
     <result column="ordertime" property="ordertime"/>
     <result column="total" property="total"/>
     <!-- <result column="uid" property="user.id"/>
     <result column="username" property="user.username"/>
     <result column="password" property="user.password"/>
     <result column="birthday" property="user.birthday"/> -->
     <!-- 
       property:当前实体(order)中的属性名称(private User user)
       javaType:当前实体(order)中的属性的类型(User)
      -->
      <association property="user" javaType="user">
        <id column="uid" property="id"/>
        <result column="username" property="username"/>
        <result column="password" property="password"/>
        <result column="birthday" property="birthday"/>
      </association>
  </resultMap>
  <select id="findAll" resultMap="orderMap">
      select *,o.id oid from orders o,user u where o.uid=u.id
  </select>
</mapper>

2.一对多查询

2.1一对多查询的模型

用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户,一对多查询的需求:查询一个用户,与此同时查询出该用户具有的订单。

<?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="com.caoyan.mapper.UserMapper">
  <resultMap id="userMap" type="user">
      <id column="uid" property="id"/>
      <result column="username" property="username"/>
      <result column="password" property="password"/>
      <result column="birthday" property="birthday"/>
      <!-- 配置集合信息
        property:集合名称
        ofType:当前集合中的数据类型
     -->
     <collection property="orderList" ofType="order">
         <!-- 封装order的数据 -->
         <id column="oid" property="id"/>
         <result column="ordertime" property="ordertime"/>
         <result column="total" property="total"/>
     </collection>
  </resultMap>
  <select id="findAll" resultMap="userMap">
    SELECT *,o.id oid FROM user u,orders o where u.id=o.uid
  </select>
</mapper>

3.多对多查询

3.1多对多查询的模型

用户表和角色表的关系为,一个用户有多个角色,一个角色被多个用户使用,多对多查询的需求:查询用户同时查询出该用户的所有角色。

 

  <resultMap id="userRoleMap" type="user">
    <!-- user的信息 -->
    <id column="userId" property="id"/>
    <result column="username" property="username"/>
    <result column="password" property="password"/>
    <result column="birthday" property="birthday"/>
    <!-- user内部的roleList信息 -->
    <collection property="roleList" ofType="role">
      <id column="roleId" property="id"/>
      <result column="roleName" property="roleName"/>
      <result column="roleDesc" property="roleDesc"/>
    </collection>
  </resultMap>
  <select id="findUserAndRoleAll" resultMap="userRoleMap">
    SELECT * FROM user u,sys_user_role ur,sys_role r where u.id=ur.userId AND ur.roleId=r.id
  </select>

4.知识小结

MyBatis多表配置方式:

  • 一对一配置:使用<resultMap>+<association>做配置
  • 一对多配置:使用<resultMap>+<collection>做配置
  • 多对多配置:使用<resultMap>+<collection>做配置
Mybatis之多表查询 MyBatis 是一个优秀的持久层框架,它提供了强大的支持来执行数据库操作,包括多表查询。多表查询是指从多个数据库表中检索数据的过程,这在实际的应用中非常常见。 阅读详情

相关推荐

MyBatis多表关联查询

一、搭建测试环境(一对多和多对一) (一)创建测试数据库 CREATE TABLE `t_teacher` ( `id` int(10) NOT NULL AUTO_INCREMENT, `name` varchar(30) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 CREATE TABLE `t_student` ( `id` int(10) NOT NUL

IceTiger_的博客 4678

Mybatis(七) - Mybatis 多表操作

表与表之间的关系: 用户表和订单表的关系为,一个用户有多个订单,一个订单从属于一个用户。 用户表和角色表的关系为,一个用户有多个角色,一个角色被多个用户使用。 一、一对一查询 1. 一对一查询的模型 一对一查询的需求:查询一个订单,于此同时查询出该订单所属的用户 2. 一对一查询的语句 SELECT *,o.id oid FROM orders o,USER u WHERE o.uid=u.id 3. 创建Order 和User 实体 pu...

yirenyuan的博客 247

MyBatis 多表关联查询

MyBatis 多表关联查询:一对多查询, 多对一查询, 自连接查询: 使用多对一的方式实现自连接, 使用一对多的方式实现自连接, 多对多查询

不迁怒,不贰过。小知识,大智慧。 4404

oracle指定多个表空间,Oracle:一个用户操作多个表空间中表的问题(转)

oracle一个用户操作多个表空间中表的问题首先,授权给指定用户. 一个用户的默认表空间只能有一个,但是你可以试下用下面的语句为其授权在别的表空间中创建对像: alter user username quota 0||unlimited on ...oracle 删除用户命令和部分表空间操作删除用户 drop user user_name cascade; 建立表空间 CREATE TABLES...

weixin_33506815的博客 1938

springboot+mybatisplus(mybatis)+mysql+oracle 多数据源项目

springboot +mybatisplus 做了一个多数据源的小项目 主要是将 mysql数据库中的数据改造放入oracle中

LVGL 9.4 性能调优实战:如何通过脏区合并与tile分块,让你的嵌入式UI流畅度翻倍

本文深入探讨LVGL 9.4中的性能优化技术,重点介绍脏区合并与tile分块如何显著提升嵌入式UI流畅度。通过实战案例和源码分析,详细解析局部刷新策略、显示框架调优及性能瓶颈诊断方法,帮助开发者在STM32、ESP32等资源受限设备上实现丝滑的UI体验。

weixin_28678831的博客 450

MyBatis系列(七)- MyBatis使用注解开发

文章目录相关文章前言注解实现CRUD①、查(select)⑤、自动提交事务 相关文章 MyBatis系列汇总:MyBatis系列 前言 注解在我们的工作当中使用的频率越来越高了,不管是学习Spring还是SpringBoot,注解开发都是必不可少的。 我们需要学习一下在Mybatis中如何使用注解开发。 以下是官方文档的原话: 使用注解来映射简单语句会使代码显得更加简洁,但对于稍微复杂一点的语句,Java 注解不仅力不从心,还会让你本就复杂的 SQL 语句更加混乱不堪。 因此,如果你需要做

大鱼的博客 426

从零搭建ROS1导航小车(一):松灵SCOUT Mini底盘通讯配置与ROS包编译避坑指南

本文详细介绍了从零开始搭建ROS1导航小车的初始步骤,重点讲解松灵SCOUT Mini底盘的通讯配置与ROS包编译避坑指南。内容包括硬件连接、CAN通讯配置、ROS工作空间构建及编译优化等实用技巧,帮助开发者快速实现自主导航小车的通讯功能。

weixin_27014595的博客 189

05MyBatis多表操作(一对一 、一对多、多对多)

数据库表之间的关系分为:一对一 、一对多、多对多 1一对一查询 用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户 一对一查询的需求:查询一个订单,与此同时查询出该订单所属的用户 表sql语句 DROP TABLE IF EXISTS `orders`; CREATE TABLE `orders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ordertime` timestamp(0) NULL DEFAULT N

技术改变世界 517

STM32巡线小车PID调参实战:从五路灰度传感器数据到稳定运行的避坑指南

本文详细介绍了STM32巡线小车的PID调参实战,从五路灰度传感器数据处理到PID参数优化,提供了系统化的调试方法和常见问题解决方案。通过加权平均法计算偏移量,逐步调整比例、积分、微分参数,实现小车稳定巡线。文章还涵盖了定时器配置、控制周期优化及高级调试技巧,帮助开发者避开常见陷阱,提升巡线性能。

weixin_42570484的博客 194

YOLOv11 网络结构详解:一文看懂 Backbone、Head、C3k2、SPPF 和 Detect 检测头

在使用 YOLOv11 进行目标检测时,我们经常会接触到或这样的模型配置文件。backbone和head分别是什么意思?ConvC3k2SPPFC2PSA这些模块分别起什么作用?P3/8、P4/16、P5/32 代表什么?为什么最后 Detect 要同时接收 3 个不同尺度的特征图?YOLOv11n、YOLOv11s、YOLOv11m、YOLOv11l、YOLOv11x 的区别在哪里?

learnerYC的博客 1816

Mybatis | 06 Mybatis多表查询**

Mybatis | 06 Mybatis多表查询Mybatis多表查询1. 四种表的关系1.1 一对多关系1.2 多对一关系1.3 一对一关系1.4 多对多关系2. 示例:用户和账户的查询2.1 相关准备2.1.1 数据库2.1.2 代码2.1.2.1 用户和账户实体类2.1.2.2 用户和账户的DAO层接口2.1.2.3 配置文件2.1.2.4 测试方法2.2 一对一查询2.2.1 使用创建子类的方式2.2.1.1 创建账户子类2.2.1.2 账户DAO层接口2.2.1.3 账户映射配置文件2.2.1.4

nothingYHN的博客 7363

【虚幻引擎UE】UE5 可编辑动态样条线轨迹及AI跟随路径移动(含工程源码)

【虚幻引擎UE】可编辑动态样条线轨迹及AI跟随路径移动

灵境引路人 6227

MyBatis—多表查询

本次主要写了关于mybatis的多表查询相关问题,延迟加载,动态sql,缓存,分页,逆向工程等功能的介绍和实现

rxdasd123456的博客 1282

注意力机制模块:二次创新:CBAM 与 ECA 融合形成 CECA 模块,参数量减少 40%

文章摘要: 本文提出一种轻量化注意力模块CECA,通过融合CBAM和ECA的优势解决模型部署中的精度与速度矛盾。CBAM虽具备通道和空间双重注意力,但参数量大;ECA轻量但缺乏空间注意力。CECA采用ECA的一维卷积替换CBAM的通道注意力部分,保留其空间注意力模块,在保持双注意力能力的同时减少40%参数量。实验表明该方案在边缘设备部署中能维持精度并提升推理速度,特别适用于YOLO等目标检测模型的轻量化改进。文章详细拆解了架构设计、代码实现及参数量优化原理,为算法工程师和嵌入式开发者提供了实用解决方案。

ZXSXJ的博客 237

使用Microsoft Print to PDF进行编程:创建PDF文件的简单方法

Microsoft Print to PDF是一种内置于Windows操作系统中的功能,它允许我们通过打印操作将任何可打印的内容保存为PDF文件。然后,我们使用Microsoft Print to PDF打印机进行打印操作,并将输出文件保存为指定的PDF文件。使用Microsoft Print to PDF功能是一种方便且简单的方法来创建PDF文件,无论是在个人使用还是在企业开发中,它都可以提供良好的支持和灵活性。请注意,如果你使用的是其他编程语言,你可以根据相应的打印机接口或库来实现类似的功能。

TechSavant的博客 1636

MyBatis实现多表查询

MyBatis实现多表查询 一、多对一查询 数据库的准备 创建两张表,一张老师表,一张学生表 将老师主键id关联学生外键tid 创建sql的语句 create table teacher( id int primary key, teacher_name varchar(30) not null ) insert into teacher(id,teacher_name) values (1,'毛老师') create table student( id int primary key

Mq_sir的博客 1万+

关闭搜狗输入法右下角广告的解决方案

本文主要介绍了关闭搜狗输入法右下角广告的解决方案,希望能对使用搜狗输入法的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

mybatis多表查询

对之前的mybatis多表查询做xml方式的补充

随便写写 2343

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

MyBatis-Plus 多表查询

MP提供了大量单表查询的方法,但是没有多表的操作,所以涉及到多表的查询时,需要我们自己实现 思路1 因为MP是基于MyBatis实现,我们可以使用MyBatis的结果映射来做,下面是一个官网的例子 https://mybatis.org/mybatis-3/zh/sqlmap-xml.html#Result_Maps <!-- 非常复杂的语句 --> <select id="selectBlogDetails" resultMap="detailedBlogResultMap"&g.

BLAZAR' 2万+

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Mybatis多表查询

对于数据库中表之间的关系有一对一、一对多、多对多。 针对于多表查询,依据表的关系,可分为一对一查询、一对多查询、多对多查询

qq_47156956的博客 849

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

JavaWeb——MyBatis框架之多表查询操作实战案例总结(MyBatis1对1查询,MyBatis1对多查询,MyBatis多对多查询)

多表之间的关系,分为一对一、一对多(多对一)、多对多,具体的不再赘述了,在数据库专栏-MySQL数据中有总结过。我们这里详细总结下MyBatis中的多表操作,所使用的工程源码会在文章末尾附上。 1 MyBatis的多表查询 以一个用户和账户的示例说明多表查询的实现步骤: 【需求】:一个用户可有多个账户(多个账户也可属于一个用户),一个账户只能属于一个用户; 【步骤】: 1)建立数据库表:用户表、账户表,在账户表添加外键,实现一对多关系; 2)建立两个实体类:用户实体类、账户实体类,实体类要...

数字世界 万物互联 2256

MyBatis 中如何使用多表查询

本文介绍了 MyBatis 中如何使用多表查询,包括使用嵌套查询、使用关联查询和使用动态 SQL 等方式。在实际开发中,我们可以根据具体的业务需求和数据结构,选择合适的方式进行多表查询。使用嵌套查询和关联查询的方式比较简单直观,适合查询较少的表,而使用动态 SQL 的方式则可以根据条件动态生成 SQL 语句,具有更高的灵活性,适合查询较多的表和复杂的数据结构。在使用 MyBatis 进行多表查询时,需要注意以下几点:确定查询的表和关系。

stormjun的博客 1798

MyBatis多表查询和注解开发

实现复杂关系映射之前我们可以在映射文件中通过配置来实现,使用注解开发后,我们可以使用@Results注解,@Result注解,@One注解,@Many注解组合完成复杂关系的配置。用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户。用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户。用户表和订单表的关系为,一个用户有多个订单,一个订单只从属于一个用户。用户表和角色表的关系为,一个用户有多个角色,一个角色被多个用户使用。多对多查询的需求:查询用户同时查询出该用户的所有角色。

write less , do more 7373
上一篇: MyBatis核心配置文件深入
下一篇: SSM整合
Caoyy686868
博客等级 码龄8年 5742粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Caoyy686868

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值