Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of iBATIS.NET Multi-table query method

Shulou Source: shulou.com Published: 2022-06-02 22:28:35 10月06日 Update

This article introduces the example analysis of iBATIS.NET multi-table query method, the content is very detailed, interested friends can refer to, hope to be helpful to you.

What is the method of iBATIS.NET multi-table query? Let's learn from examples step by step:

Create two tables Account and Degree, use Account_ID association, and need to find out all the records of the two tables.

First, modify the entity class by adding the following attributes:

Private Degree _ degree; public Degree Degree {get {return _ degree;} set {_ degree = value;}}

Then: modify the configuration file, which is also the most important part (the configuration file in PS:iBATIS.NET is really strong)

In the resultMaps section, add:

< resultMap id= "com2result" class= "Account" > < result property= "Id" column= "Account_ID" / > < result property= "FirstName" column= "Account_FirstName" / > < result property= "LastName" column= "Account_LastName" / > < result property= "EmailAddress" column= "Account_Email" nullValue= "no_email@provided.com" / > < result property= "Degree" resultMapping= "Account.Degree-result" / > < resultMap id= Degree-result "class=" Degree "> < result property=" Id "column=" Account_ID "/ > < result property=" DegreeName "column=" DegreeName "/ > < / resultMap >

The most important thing here is to use the resultMapping attribute, resultMapping= "Account.Degree-result", where Account is the namespace of the current configuration file:

< sqlMap namespace= "Account".

In the states section, add:

< select id= "GetCom2Tables" resultMap= "com2result" > select Accounts.*, Degree.* from Accounts,Degree where Accounts.Account_ID = Degree.Account_ID < / select >

In this way, you can write the sql you need as much as you like, and the performance is very good, so that there will not be a query statement of 1roomn in the third method.

Then, iBATIS.NET multi-table query method will be introduced to you here, I hope it will be helpful for you to understand iBATIS.NET multi-table query method.

This is the end of the sample analysis of the iBATIS.NET multi-table query method. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Methods queries files help configuration examples analysis content properties more good important freewheeling interests places entities instances guys buddies that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Information MariaDB Shulou Tech Info