Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the wrong way to use MyBatis resultMap id tags?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today I will show you what is the wrong way to use MyBatis resultMap id tags. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

Incorrect use of MyBatis resultMap id tags

We are writing VO objects, and if the business scenario is a little more complex, we will use the collection properties. For example, users view a list of personal orders, and each order contains items of multiple or more specifications.

The main problem in this section is my misuse of the mybatis id tag

Id is a child tag of resultMap and Collection, and it is marked as a result of ID that can help improve overall performance. In particular, id is a unique identity in the current namespace that identifies a result mapping.

As shown in the figure below, the value of the itemId (goods id) field is not unique in the database, and misuse will result in only one record of an item for the order. Because for a commodity, spicy taste and five fragrances are only commodity specifications, and the product id is the same.

After switching to the normal result tag, the correct result is returned.

EOF

Use rules for resultMap tags to customize the result mapping rules select * from employee where id=# {id} association federated query

Association can specify federated javabean objects

Property= "dept": specify which attribute is the federated object

JavaType: specify the type of this property

Select e.id id,e.name empName,e.email email,e.sex sex,e.d_id d_id, d.id did,d.name deptName from employee eQuery dept d where e.d_id=d.id and e.id=# {id} using association for distributed query

1. Querying employee information according to employee id will call the sql of querying employee.

2. Go to the department table to find the department information according to the d _ id value in the employee information query.

3. Set up the department to the employees

Select * from employee where id=# {id}

Nesting result sets, using collection tags to define attribute encapsulation rules for associated collection types

Select d.id did,d.name deptName,e.id eid, e.name empName,e.sex E.email from dept d left join employee e on d.id=e.d_id where d.id=# {id} collection step by step query select * from employee where d_id=# {deptId} select * from dept where id=# {id}

When a distributed query needs to pass multiple values, encapsulate multiple values in map delivery

Colum= "{key1=column1,key2=colum2...}" above is the whole content of what is the wrong use of MyBatis resultMap id tags, and more content related to the wrong use of MyBatis resultMap id tags can search previous articles or browse the following articles to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report