Spring framework configuration entity class complex attribute injection XML file process details

Spring framework is a very important framework in Java Web projects. Most web projects are divided into persistence layer, service layer and control layer. The persistence layer (Dao, mapper) is used to connect the database and complete the transfer of data between the project and the database; The service layer mainly completes various businesses (addition, deletion, modification and query) in the project, connects the persistence layer and the control layer, and also deals with various entity classes, while the control layer mainly deals with web front-end pages and transmits data with pages.

Today, we will mainly introduce the service layer framework spring, which is also the core framework of various integration frameworks. This paper mainly introduces a small knowledge point in spring, which is difficult to remember, that is, the di (injection) of entities in the spring framework, that is, the injection methods of complex data types in entity classes, such as arrays, map sets, set sets, properties and lists.

First, create an entity class, and the setter and getter methods go through a wave

Various types of attributes are defined in the entity class

Here, write the bean tag in your configuration file XML. The ID is the unique ID, which should be used through the ID. the class is the path of the entity class. Select the attribute name in the entity class through the name in the attribute tag property, which is obtained here through the get method

Array sets the array value through multiple value attributes in set

This is the injection of list type data. List is the array tag and value is the value

Set data injection, list tag

Map type data injection, props tag

Properties type, data injection, map tag

The above is the injection method of these complex types. You can see that the labels of these data types are confused with each other. I don't know who invented this thing. No one remembers this thing. If you use it, you can check it directly.

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>