Mybatis快速上手4 关联表查询二:一对多表关联查询

Java中的多表条件查询 开发工具与关键技术:Eclipse 带条件多表联查 作者:廖 茂 撰写时间:2020年08月08日 在初步进入Java语言的学习后,发现java中的逻辑思想和C#的逻辑思想几乎一致,当然只是逻辑思想,要实现功能的具体实现代码还是不同的,毕竟语言不同,在java中要实现对数据库(MySQL数据库)中的数据进行增删改查这些操作,主要是通过SQL语句来实现的,也就短短几句代码就能对数据库中的数据进行操作,但是要把这些操作体现在页面上就需要一些方法来实现了,接下来我们来看一下如何实现带条件的多表联查,首先我们来 阅读详情

其他章节及开发包:https://blog.youkuaiyun.com/XIMAX/article/details/106255196

环境 :Eclipse+Tomcat9+JDK10+Mybatis-3.1.1、Navicat

在这里插入图片描述
test1~8分别对应八章,本章使用包test4、tool,文件config.xml、db.properties、log4j.properties

需求

根据classId查询对应的班级信息,包括学生,老师

代码

建库,建表

CREATE TABLE student(
 s_id INT PRIMARY KEY AUTO_INCREMENT, 
 s_name VARCHAR(20), 
 class_id INT
);

INSERT INTO student(s_name, class_id) VALUES('xs_A', 1);
INSERT INTO student(s_name, class_id) VALUES('xs_B', 1);
INSERT INTO student(s_name, class_id) VALUES('xs_C', 1);
INSERT INTO student(s_name, class_id) VALUES('xs_D', 2);
INSERT INTO student(s_name, class_id) VALUES('xs_E', 2);
INSERT INTO student(s_name, class_id) VALUES('xs_F', 2);

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  <properties resource="db.properties"></properties>
  <typeAliases>
    <package name="com.rjxy.test4"/>
 <typeAliases>
 
 <typeAliases>
   <package name="com.rjxy.test2"/>
 <typeAliases>
 <environments default="development">
   <environment id="development">
    <transactionManager type="JDBC" />
    <dataSource type="POOLED">
     <property name="driver" value="${driver}" />
     <property name="url" value="${url}" />
     <property name="username" value="${username}" />
     <property name="password" value="${password}" />
    </dataSource>
   </environment>
  </environments>  
 
 <mappers>
   <mapper resource="com/rjxy/test4/userMapper.xml"/>
 <mappers>
</configuration>

userMapper.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="com.rjxy.test4.userMapper">
<!-- 一对多关联 method1 联表查询 -->
 <select id="getClass" parameterType="int" resultMap="getClassMap">
  select * from class c,teacher t, student s where c.teacher_id=t.t_id and c.c_id=s.class_id and c.c_id=#{id}
 </select>
 
<resultMap type="Classes2" id="getClassMap">
  <id property="id" column="c_id"/>
  <result property="name" column="c_name"/>
  <association property="teacher" javaType="Teacher">
   <id property="id" column="t_id"/>
   <result property="name" column="t_name"/>
  </association>
  <collection property="students" ofType="Student">
   <id property="id" column="s_id"/>
   <result property="name" column="s_name"/>
  </collection>
 </resultMap> 

!-- method2 嵌套查询 -->
告别硬编码SQL:mybatis-plus-join 实现多表关联查询的优雅实践 本文详细介绍了如何使用mybatis-plus-join实现多表关联查询的优雅实践,告别硬编码SQL带来的维护难题。通过LambdaWrapper和QueryWrapper的对比分析,展示了类型安全与灵活性的平衡,并提供了处理一对多关系、动态表别名管理等进阶技巧,帮助开发者提升代码可读性和维护效率。 阅读详情

相关推荐

若依框架实战:基于Mybatis与ruoyi-vue实现OA系统一对一关联查询

本文详细介绍了如何在若依框架(ruoyi-vue)中基于Mybatis实现OA系统的一对一关联查询。通过数据库表设计、SQL优化、代码生成器使用、Mybatis映射配置及前端Vue组件展示等实战步骤,帮助开发者掌握高效的数据关联查询技术,提升OA系统开发效率。

weixin_28455801的博客 268

Mybatis-puls自定义查询扩展方案

当前很多开源的低代码平台框架多对mybatis-puls进行了查询的封装使得使用起来很方便如:jeecg-boot, bladex等通过前后端协商约定基于mybatis-pulus 构造QueryWrapper能够快速实现各种条件的查询。但是存在局限性因为mybatis-pulus 的基础查询方法目前只支持单表查询,这对一些复杂的查询场景而言就比较难以支持必须自己写mapper 组织组织查询条件。那有没有一种可以关联表的工具也支持LambdaWrapper?答案是存在的做连接查询的插件。..........

keyi300的博客 4241

eclipse关联实体查询

关联实体查询 java源程序,eclipse环境,运行结果是节点和关联关系值

欧姆龙多PLC串行链接模式的应用

欧姆龙多PLC串行链接模式的应用 一、如何将两台CP1H进行串行PLC连接(PLC串行链接) 主机侧设定 从机侧设定 二、 如何实现编程通信 主机侧的【PC连接模式】为【全部】的时候 ① 主机会把自己的地址从3100开始,按照【链接字】设定的字数个数发送到每个从机的3100开始进行存储。 ② 从机会把自己的地址从31n0开始,按照主机侧参数【链接字】设定的字数个数发送到主机的31n0开始进行存储。 注:(n为从机的地址号,若从机号不连续,则该编号的地址将不被定义..

u014202847的博客 3090

深度学习|卷积神经网络

介绍卷积神经网络基本理论,包括卷积层、池化层和全连接层,并阐述LeNet卷积神经网络的构建过程。

weixin_58243219的博客 5727

Python之美——Python2与Python3多版本共存

Python多版本共存的方法Python2、Python3共存的方法python2下载及环境变量配置第一步、打开Python官网,下载Python2第二步、python2环境变量配置测试结果 Python2、Python3共存的方法 方法如下: 1.先确保不同版本解释器的python.exe所在的路径在环境变量中 2.拷贝各自的python.exe并重命名即可 步骤(理解不了下面有图示): 1、首先你需要将不同的python版本安装,且都已经将跟版本的环境变量配置好了,python3和2的下载方式

chenchen5152的博客 3946

人类肠道微生物群落代谢建模

MICOMWeb 是款用户友好型网站,专为人类肠道微生物群落代谢建模设计。该网站旨在解决基因组尺度代谢模型(in silico)构建过程中的3大限制:① 使用 MICOM Python 包进行通量平衡分析时对用户 Python 编程知识的要求;② 支持预定义和用户自定义饮食,以生成专属代谢模型;③ 处理宏基因组鸟枪法测序或 16S 扩增子测序获得的真实丰度数据时,所需的高通量计算基础设施。本文展示了 MICOMWeb 的核心功能,用户可轻松开展虚拟实验,为3个已发表数据集的实验验证生成功能性假设。

多组・学・多组学 1171

bcftools学习笔记(一)

欢迎关注&#34;生信修炼手册&#34;!本篇主要介绍index, view, query, sort, reheader这五个命令。1. indexindex命令用于对VCF文件建立索...

庐州月光的博客 6012

睿尔曼超轻量仿人机械臂-ROS第一篇 启动机械臂的Moveit

本文主要讲述了睿尔曼六轴机械臂在ROS中的功能包配置,及如何根据文件启动Moveit做仿真。

realman_Rop的博客 7490

Cursor 详细使用

Cursor 是一款基于 VSCode 开发的 AI 驱动代码编辑器,集成 GPT-4、Claude3.5 等先进 LLM,具备代码补全、生成、解释、调试等功能,可提升开发效率和代码质量。3. 代码编辑:在编辑区编写代码,利用快捷键提升效率,如 Ctrl+Space 触发智能代码补全、Ctrl+K 润色或修改代码、Ctrl+L 智能问答与代码编辑。3. 代码解释:选中代码,按 Ctrl+L,输入如 “解释这段代码的功能”,Cursor 会给出详细解释。

坚持写博客,大家的关注是我前进的动力! 4817

【电动汽车再生制动控制技术(万字长文,图文并茂)】

电动汽车再生制动的基本原理是:通过具有可逆作用的电动机/发电机来实现电动汽车动能和电能的转化。在汽车减速或制动时,可逆电机以发电机形式工作,汽车行驶的动能带动发电机将汽车动能转化为电能并储存在储能器(蓄电池或超级电容器)中;在汽车起动或加速时,可逆电机以电动机形式工作,将储存在储能器中的电能转化为机械能给汽车。这对于改善汽车的能量利用效率,延长电动汽车的行驶距离是至关重要的。

优快云-新能源汽车研发测试专业博主 1579

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

深度学习工具包 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")

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

上一篇: Mybatis快速上手3 关联表查询一:一对一表关联查询
下一篇: Mybatis快速上手5 模糊查询和动态SQL
执力
博客等级 码龄7年 3粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值