Introduction to the parameters in Statement:
ParameterClass
The value of the ParameterClass property is the full-qualification of the Java class (ie, including the package name). The ParameterClass property is optional, the purpose is to limit the type of input parameter to the specified Java class. Although Parameter-Class properties are optional, it is recommended that you specify parameterclass for each SQL. If the ParameterClass parameter is not specified, any Java bean with appropriate properties (Get / Set method) can be used as an input parameter. If you use ParameterMap, then you don't need to use the parameterclass property.
Here is an example:
example 1:
INSERT INTO AUTHOR (auth_name, auth_age, auth_tel, auth_address) values (#Name #, # age #, # Telephone #, # address #)
INSERT>
In the above statement, you specified ParameterClass = Author, then there are Name, Age, Telephone, and Address properties in your Author class, and have corresponding GET and SET methods
Example 2:
You can use basic types as parameterclass, such as:
Delete from author where auth_id = # id #
delete>
Example 3:
You can use Hashmap as parameterclass, such as:
INSERT INTO AUTHOR (auth_name, auth_age, auth_tel, auth_address) values (#Name #, # age #, # Telephone #, # address #)
INSERT>
At this time, when you call INSERTAUTHOR3, you should first assign a value to the incoming MAP object, the call code is as follows:
Hashmap paramap = new hashmap ();
Parammap.put ("Name", "author three");
Parammap.put ("age", new integer (31));
Parammap.put ("Address", "Nanjing");
Parammap.Put ("Telephone", "025-987654321");
SqlmapClient.insert ("INSERTAUTHOR3", Parammap;
2. ParameterMap
ParameterMap Defines a series of sequenceful parameters to match the JDBC value symbol of PreparedStatement.
ParameterMap properties are rarely used, and the value of ParameterMap attributes is equal to the Name property value of the specified parametermap element. Usually (and default) methods are in -line parameters.
note! Dynamic mapped state means only supports Inline Parameter, and Parameter Map is not supported. Regarding the dynamic mapped statement, it will be described later. E.g:
parametermap>
INSERT INTO AUTHOR (auth_name, auth_age, auth_tel, auth_address) VALUES (?,?,?,?)
INSERT>
In the above example, ParameterMap parameters match the value symbols in the SQL statement in order. Therefore, the first "?" Number will be replaced by the value of the "name" attribute, and the second "?" Number will be replaced by the value of the "agn" property, and so on.
Remember: When using parametermap, the parameters in SQL are replaced by "?", And each "?" Order fully matches the definition in ParameterMap; if you use parameterclass, then the parameter in SQL "# parametername # "Instead, if the incoming parameter class is bean, then there is a method of GET and SET this parameter name.
3. Resultclass
The resultClass property allows you to specify a Java class, automatically map it to the JDBC Resultset based on ResultSetMetadata. As long as it is a JavaBean property, the method name, and the column name of the Resultset, the property is automatically assigned value.
example 1:
SELECT Auth_id As ID, Auth_name As Name, Auth_age As Age, Auth_tel As Telephone, Auth_address As Address from Author WHERE Auth_Id = #ID # select>
In the above statement, you specified ResultClass = Author, then there are ID, name, age, telephone, and address properties in your Author class, and have the corresponding GET and SET methods.
If you write:
Select auth_id, auth_name, auth_age, auth_tel, auth_address from author where auth_id = # id #
select>
So in your Author class, there must be auth_id, auth_name, auth_age, auth_tel, auth_address attribute, and have corresponding GET and SET methods.
Example 2:
You can also use basic types as Resultclass, such as:
statement>
Example 3:
You can also use Hashmap as Resultclass, such as:
SELECT a.auth_id as authorid, a.auth_name as authname, a.auth_age as authage, a.auth_tel as authtel, a.auth_address as authaddress, b.art_title as arttitle FROM author a, article b WHERE a.auth_id = b.art_author
select>
Here is called code:
List authorlist = (list) SQLMAPCLIENT.QUERYFORLIST ("GetAuthor4", NULL);
ShowMethod ("getAllauThor");
For (int i = 0; i { Hashmap authmap = (havehmap) AuthorList.get (i); System.out.println ("auth_id =" authmap.get ("authid") "; auth_name =" authmap.get ("authname") "; author_age =" authmap.get ("Authage") "; Auth_tel =" authmap.get ("authtel") "; auth_address =" authmap.get ("authaddress") "; auth_article =" authmap.get ("arttitle"));} However, there are some restrictions in the automatic mapping of ResultClass, and the data type of the output field cannot be specified, and the related data (complex attributes) cannot be automatically loaded, and the performance will be slightly adversely affected by the performance of ResultSetMetadata. But use RESULTMAP, which can be easily resolved. 4. Resultmap: Use the ResultMap property to control the data how to take out from the result set and which property matches which field. The resultMap property can allow the specified field data type, NULL's alternate value. E.g: resultMap> Select auth_id, auth_name, auth_age, auth_tel, auth_address from author where auth_address like #% address% # select> or SELECT * AUTHOR statement> In the above statement, you specified ResultClass = Author, then there are ID, name, age, telephone, and address properties in your Author class, and have the corresponding GET and SET methods. With the definition of ResultMap, the resultSet obtained by the query statement is mapped to the Author object. ResultMap Defines the "ID" attribute value will give the "Auth_ID" field value, and the "Telephone" property value will give the "Auth_tel" field value, and push it according to the class. Note: The fields specified in the ResultMap must be the subset of the following SELECT. In other words, you can't write Select auth_address from author where auth_address like #% address% # select> But you can remove the Select auth_id, auth_name, auth_age, auth_tel, auth_address from author where auth_address like #% address% # select> In this way, you cannot get the value of auth_id. 5. Cachemodeel Define the cache of the Mapped Statement. Each query mapped statement can use different or identical Cachemodel. cachemodel> Select auth_id, auth_name, auth_age, auth_tel, auth_address from author where auth_address like #% address% # select> The above configuration description: The cache of "GetAuthor3" uses the Weak reference type. When you call "getAuthor3", iBATIS will cache the results. Refresh every 24 hours, or updated (i.e., INSERTPRODUCT, UPDATEPRODUCT, or DELETEPRODUCT) configured above. When you frequently perform frequent records in some tables, you can consider using buffers, but if the amount of data is too large, it is best to find a way. 6. XmlResultName When the mapping result points to an XML document, the value of XMLResultName refers to the name of the root tag of the XML document. E.g: SELECT Auth_id As ID, Auth_name As Name, Auth_age As Age, Auth_tel As Telephone, Auth_address As Address from Author WHERE Auth_Id = # id # select> The above SELECT will produce the following XML object:
author>
