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 are the ways of writing Mapper

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

Share

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

This article is to share with you about the way Mapper is written. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What are the ways to write Mapper?

First: interface implementation class inherits SqlSessionDaoSupport: to use this method, you need to write mapper interface, mapper interface implementation class, mapper.xml file.

(1) configure the location of mapper.xml in sqlMapConfig.xml

(2) define mapper interface

(3) implement class integration SqlSessionDaoSupport

In the mapper method, you can add, delete, modify and query data by this.getSqlSession ().

(4) spring configuration

The second is to use org.mybatis.spring.mapper.MapperFactoryBean:

(1) configure the location of mapper.xml in sqlMapConfig.xml. If the names of mapper.xml and mappre interfaces are the same and in the same directory, you do not need to configure them here.

(2) define the mapper API:

(3) namespace in mapper.xml is the address of mapper interface

(4) the method name in the mapper interface is consistent with the id of the statement defined in mapper.xml.

(5) defined in Spring

Third: use mapper scanners:

(1) mapper.xml file writing:

Namespace in mapper.xml is the address of the mapper interface

The method name in the mapper interface is consistent with the id of the statement defined in mapper.xml

If you keep the names of the mapper.xml and mapper interfaces the same, you do not need to configure them in sqlMapConfig.xml.

(2) define the mapper API:

Note that the file name of mapper.xml is the same as the interface name of mapper and is placed in the same directory

(3) configure mapper scanner:

(4) obtain the implementation object of mapper from the spring container after using the scanner.

Thank you for reading! This is the end of this article on "what are the ways of writing Mapper?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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