Ibatis.net Series (5) Parametermap

xiaoxiao2021-03-31  191

Using

ADO.NET

The most troublesome is preparing for database access operations.

DBCommand

Must add it to it

DBParameter

, Especially when the parameters of the page are particularly more, many of the code of the data access layer are flown here.

Ibatis

of

Parametermap

The configuration is a solution proposed for this issue, based on

xml

Configuration, put the field name and object's properties, and automatically

DBCommand

Provides the set of parameters it needs. Thus, we write a lot of repetition code directly.

In the Employees_ParameterMap.xml configuration file:

Select Employeid, Lastname, Firstname from Employees Where EmployeeiD = # Employeeid # or lastname = # lastname # or country = # Country #

The ParameterMap it uses is as follows:

In each parameter mapping element, you can specify the columns corresponding to each property, its type, and the type of corresponding database, you can specify the default value when it is null, specifically, you can see the official document. However, it can be seen that we look forward to the same way as the inline parameters, as described above. But can't you do it? From the execution result of the program, it is not possible. Due to the previous configuration of the SQL statement, it is basically noticed to use the inline parameters. When using the parameter map, you cannot display the property parameters you want to use in the form of # proty #, can only replace each parameter element in order, as follows:

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