In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will give you a detailed explanation on how to avoid ibatisN+1 queries. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Java code avoids ibatisN+1 queries
Multi-party:
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
}
}
One party:
Public class Department {
Private int did
Private String departmentName
Private Listemployees
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 ListgetEmployees () {
Return employees
}
Public void setEmployees (Listemployees) {
This.employees = employees
}
}
Multi-party:
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
}
}
One party:
Public class Department {
Private int did
Private String departmentName
Private Listemployees
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 ListgetEmployees () {
Return employees
}
Public void setEmployees (Listemployees) {
This.employees = employees
}
}
If you want to avoid ibatisN+1 queries while working on mapping files, you can refer to the following code.
Xml code avoids ibatisN+1 queries
Multi-party:
1. xml version= "1.0" encoding=" UTF-8 "? >
two。
3.
4. PUBLIC "- / ibatis.apache.org//DTD SQL Map 2.0//EN"
5. "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
6.
7. < sqlMap namespace= "Employ" >
8.
9.
10. < typeAlias alias= "Employ" type= "com.test.domain.Employ" / >
11.
12.
13. From a query, and the class properties. A result map isn't
14. Necessary if the columns (or aliases) match to the properties
15. Exactly. -- >
16. < resultMap id= "EmployResult" class= "Employ" >
17. < result property= "id" column= "id" / >
18. < result property= "enployName" column= "employ_name" / >
19. < result property= "salary" column= "salary" / >
20. < result property= "department.did" column= "did" / >
21. < result property= "department.departmentName" column= "department_name" / >
twenty-two。 < / resultMap >
23.
24.
25. < select id= "selectAllEmploy" resultMap= "EmployResult" >
twenty-six。
twenty-seven。 Select * from employees e, departments d where e.departmentid = d.did
twenty-eight。 ]] >
twenty-nine。 < / select >
thirty。
thirty-one。 Aliases to match the properties of the target result class. -- >
thirty-two。
thirty-three。
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.