博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mybatis性能优化二之多对多查询:用一次请求解决n次请求查询
阅读量:6160 次
发布时间:2019-06-21

本文共 3461 字,大约阅读时间需要 11 分钟。

以上是优化的结论:用一次请求解决n次请求查询

题目:在teacher 表中找到该 teacher下面的n个student并找出n个学生每个学生有多少个goods。

sql:

CREATE TABLE  teacher  (   id number  NOT NULL  ,  name varchar(100) DEFAULT NULL,  PRIMARY KEY (id)) ;CREATE TABLE  student  (  sid number  NOT NULL  ,  sname varchar(100) DEFAULT NULL,  t_s_id number  NOT NULL  ,  PRIMARY KEY (sid) ) ; insert into teacher(id,name) values(111,'zhangsan'); insert into teacher(id,name) values(222,'lisi'); insert into student(sid,sname,t_s_id) values(1,'xs1',111); insert into student(sid,sname,t_s_id) values(2,'xs2',111); insert into student(sid,sname,t_s_id) values(3,'xs3',222); insert into student(sid,sname,t_s_id) values(4,'xs4',111); select * from student;select * from teacher;select t.id,t.name,s.t_s_id,s.sid,s.sname		from teacher t     left join student s     on t.id = s.t_s_id where t.id = 111             create table goodItem(     gid number not null,     goodName varchar(10),     price float,     good_sid number    )        insert into goodItem(gid,Goodname,Price,Good_Sid)    values(1,'iphone6','6000',2);    insert into goodItem(gid,Goodname,Price,Good_Sid)    values(2,'iphone5','5000',2);    insert into goodItem(gid,Goodname,Price,Good_Sid)    values(3,'iphone4','4000',2);     insert into goodItem(gid,Goodname,Price,Good_Sid)    values(4,'iphone3','3000',1);

vo:

package com.cn.vo;public class Student {	private int sid;	private String sname;	public int getSid() {		return sid;	}	public void setSid(int sid) {		this.sid = sid;	}	public String getSname() {		return sname;	}	public void setSname(String sname) {		this.sname = sname;	}	 }

package com.cn.vo;import java.util.List;public class Teacher {	private int id;	private String name;	private List
students; private List
goods; public List
getGoods() { return goods; } public void setGoods(List
goods) { this.goods = goods; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List
getStudents() { return students; } public void setStudents(List
students) { this.students = students; }}
package com.cn.vo;public class Item {	private  Integer  gid;	private String goodName;	private float price;	private Integer good_sid;	public Integer getGid() {		return gid;	}	public void setGid(Integer gid) {		this.gid = gid;	}	public String getGoodName() {		return goodName;	}	public void setGoodName(String goodName) {		this.goodName = goodName;	}	public float getPrice() {		return price;	}	public void setPrice(float price) {		this.price = price;	}	public Integer getGood_sid() {		return good_sid;	}	public void setGood_sid(Integer good_sid) {		this.good_sid = good_sid;	}		}

package com.cn.vo;import java.util.List;public class GoodItem extends Item{/*	private List
students; private List
teachers; public List
getStudents() { return students; } public void setStudents(List
students) { this.students = students; } public List
getTeachers() { return teachers; } public void setTeachers(List
teachers) { this.teachers = teachers; } */ }

转载地址:http://sulfa.baihongyu.com/

你可能感兴趣的文章
跨域-学习笔记
查看>>
the assignment of reading paper
查看>>
android apk 逆向中常用工具一览
查看>>
MyEclipse 报错 Errors running builder 'JavaScript Validator' on project......
查看>>
Skip List——跳表,一个高效的索引技术
查看>>
Yii2单元测试初探
查看>>
五、字典
查看>>
前端js之JavaScript
查看>>
Log4J日志配置详解
查看>>
实验7 BindService模拟通信
查看>>
scanf
查看>>
Socket编程注意接收缓冲区大小
查看>>
SpringMVC初写(五)拦截器
查看>>
检测oracle数据库坏块的方法
查看>>
SQL server 安装教程
查看>>
Linux下ftp和ssh详解
查看>>
跨站脚本功攻击,xss,一个简单的例子让你知道什么是xss攻击
查看>>
js时间和时间戳之间如何转换(汇总)
查看>>
js插件---图片懒加载echo.js结合 Amaze UI ScrollSpy 使用
查看>>
java中string和int的相互转换
查看>>