Ibatis N:1避免N+1查询的方法
来源:互联网 发布:日本侵华成功知乎 编辑:程序博客网 时间:2024/09/21 06:38
一、实体类
多方:public class Employ {private int id;private String enployName;private int salary;private Department department;public Employ() {}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getEnployName() {return enployName;}public void setEnployName(String enployName) {this.enployName = enployName;}public int getSalary() {return salary;}public void setSalary(int salary) {this.salary = salary;}public Department getDepartment() {return department;}public void setDepartment(Department department) {this.department = department;}}一方:public class Department {private int did;private String departmentName;private List<Employ> employees;public int getDid() {return did;}public void setDid(int did) {this.did = did;}public String getDepartmentName() {return departmentName;}public void setDepartmentName(String departmentName) {this.departmentName = departmentName;}public List<Employ> getEmployees() {return employees;}public void setEmployees(List<Employ> employees) {this.employees = employees;}}
二、映射文件
多方:<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="Employ"> <!-- Use type aliases to avoid typing the full classname every time. --> <typeAlias alias="Employ" type="com.test.domain.Employ"/> <!-- Result maps describe the mapping between the columns returned from a query, and the class properties. A result map isn't necessary if the columns (or aliases) match to the properties exactly. --> <resultMap id="EmployResult" class="Employ"> <result property="id" column="id"/> <result property="enployName" column="employ_name"/> <result property="salary" column="salary"/> <result property="department.did" column="did"/> <result property="department.departmentName" column="department_name"/> </resultMap> <!-- Select with no parameters using the result map for Account class. --> <select id="selectAllEmploy" resultMap="EmployResult"> <![CDATA[ select * from employees e, departments d where e.departmentid = d.did ]]> </select> <!-- A simpler select example without the result map. Note the aliases to match the properties of the target result class. --> <!-- Insert example, using the Account parameter class --> <insert id="insertEmploy" parameterClass="Employ"> <![CDATA[ insert into employees (employ_name, salary, departmentid) values(#enployName#, #salary#, #department.did#) ]]> </insert> <!-- Update example, using the Account parameter class --> <!-- Delete example, using an integer as the parameter class --></sqlMap>一方:<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="Department"> <!-- Use type aliases to avoid typing the full classname every time. --> <typeAlias alias="Department" type="com.test.domain.Department"/> <!-- Result maps describe the mapping between the columns returned from a query, and the class properties. A result map isn't necessary if the columns (or aliases) match to the properties exactly. --> <resultMap id="DepartmentResult" class="Department"> <result property="did" column="did"/> <result property="departmentName" column="department_name"/> </resultMap> <!-- Select with no parameters using the result map for Account class. --> <select id="selectDepartmentById" parameterClass="int" resultMap="DepartmentResult"> <![CDATA[ select * from departments where did = #did# ]]> </select> <!-- A simpler select example without the result map. Note the aliases to match the properties of the target result class. --> <!-- Insert example, using the Account parameter class --> <insert id="insertDepartment" parameterClass="Department"> <![CDATA[ insert into departments (department_name) values(#departmentName#) ]]> </insert> <!-- Update example, using the Account parameter class --> <!-- Delete example, using an integer as the parameter class --></sqlMap>
0 0
- Ibatis N:1避免N+1查询的方法
- iBatis学习(五) 避免SELECT N+1
- ibatis 复杂类型属性(自定义类型的属性) 避免n+1次select(1:1)
- ibatis N+1问题
- hibernate ibatis n+1
- ibatis N+1问题
- iBATIS多表查询之N+1 Select
- iBATIS中1:N查询结果利用groupBy功能实现的简单配置
- n&n-1 n&-n
- n&-n n&n-1
- 什么是N+1查询?
- hibernate n+1查询
- 什么是N+1查询?
- N+1查询
- N+1查询问题
- 什么是N+1查询?
- iBatis n+1选择问题 的几种解决方案
- IBatis学习关于N+1问题的解决
- oracle添加列
- API Guides(五)——<Activity> To Dialogs
- 禁用select,使select失去作用
- ibatis基础开发
- 很久没有来更新了
- Ibatis N:1避免N+1查询的方法
- 帮一个初学者朋友写的矩阵加法
- [iOS]Storyboard的爱与恨
- 软件测试基础
- 求两个时间段间的工作日(周一到周五)
- mysql存储过程--返回两个时间的最大最小值
- 对ibatis封装
- 使用注解做添加删除修改
- nltk(2)——频率分布&词操作