Ibatis.net Series (6) Resultmap

xiaoxiao2021-03-31  216

Since the May 1st, three

Ibatis.net

of

POST

Once, there has been no update related articles. On the one hand, because of its own ability, it is not confident, and the three convictions have not been confident in the home page. On the other hand, because it is really busy recently, you can make me busy to turn around, there is no time to take time.

Blog

. But think about it, just an excuse, see

DFLYING CHEN

In these two months

CNBLOGS

The achievements made let me be embarrassed, it is impossible to compile with others, but always take "busy" to block the Wrigley, it shouldn't.

After the wine, enter this theme, we will discuss a very important content in iBatis, in my personal opinion, can really use the key to ibatis, this is Resultmap. Field understanding, it is the mapping of the result set, which is to assign a map to the object's properties of the object. In fact, if there is no special needs, we can use ResultClass to replace it, because if the field is exactly the same as the property, querying the data set automatically matches the instance object of the class specified by the resultClass, if the field name is not in the property, then this field will The instance objects that will not be returned are accepted, which is equivalent to not querying this field.

Each ResultMap has an id, if you are not configured with namespace in SQLMap.config, then this ResulTemap ID is a full bureau (this is the same in all IBATIS configuration elements), an important property of Resultmap The class is Class, which will determine the class of the example of this Resultmap, in other words, it is to indicate the data type of the result set. In the Extends property, it can set the resultMap to inherit, if the value is given to him, then it will inherit the map configuration field from the Super Resultmap. Defined as follows:

If you have correctly configured the ibatis XSD architecture file, then this time you will prompt the definition of ResultMap is incomplete. That's right, next is to define the Result element. Each Result element is a mapping that defines a field with a data class property. There is a relatively large attribute parameter in each Result element, where Property and Column are required, and other parameter properties are optional. So we must define more than more than one Result definition in every Resultmap. Often the following configurations can complete the basic configuration.

But if you need more requirements, the Result Map can still maximize you. The ColumnIndex property provides the program we map the proprietary item of the data set to the specified data object properties, but this way should be as small as possible, you will find that this will result in the maintenance and readability of us. Very large side effects. The DBTYPE attribute clearly indicates the type of database corresponding to this field, and I rarely use most cases. The Type property clearly indicates the data type of this field to attribute the corresponding data object properties, usually if you want to guarantee type security, setting this property is necessary. The resultMapping property is slightly more complicated, which is used in a scenario, if a data class's attribute itself is not a primitive data type, but a complex data type, then we can't give it a simple The result element is about, but also gives him a complete resultmap. The resultMapping property is to do this. Its attribute value is an ID of an existing resultMap. NullValue properties have nothing to say, it is given when the value of this field is null, how much is its default value. SELECT attributes are more complicated as resultmapping, first talking about its attribute value must be a ID of the query statement that returns a data set, and the data class attribute that can be configured can be a primitive type, composite type, or one Includes a set type of multiple data, these types, no problem. Its important existence is to describe the relationship between different tables. Through this query, you can use the select property when you query the relevant fields from another table, you don't want to query the relevant fields from another table. As follows:

CopyRight © 2020 All Rights Reserved
Processed: 0.038, SQL: 9