Java-MyBatis-MyBatis3-XML mapping file: select

ylbtech-Java-MyBatis-MyBatis3-XML mapping file: select

 

1. Back to top
1、

select

MyBatis statement is one of the most commonly used elements, light can save data to the database value is not large, can only be taken out to be useful again, most applications are also frequently than the query to modify. For each insert, update, or delete operation, usually separated by multiple queries. This is one of the basic principles of MyBatis, and is the focus and effort on the results of the query and mapping of reasons. select elements of simple queries is very simple. such as:

<select id="selectPerson" parameterType="int" resultType="hashmap"> SELECT * FROM PERSON WHERE ID = #{id} </select>

This statement is called selectPerson, a receiving int (or Integer) type parameter and returns the object type of a HashMap where the key is the column name, the corresponding value is the value of the result row.

Note Parameter Symbol:

#{id}

This tells MyBatis to create a prepared statement (PreparedStatement) parameters in JDBC, such a parameter in SQL will be identified by one and transferred to a new prepared statement, like this "?":

// approximate JDBC code and the code of non-MyBatis ... String selectPerson = "the SELECT * the FROM PERSON the WHERE ID =?" ; PreparedStatement PS = conn . PrepareStatement ( selectPerson ); PS . SetInt ( 1 , the above mentioned id );
  

Of course, using JDBC means more code to extract the results and map them to the object instance, and this is what MyBatis saves you time. Parameters and results as well as more in-depth mapping details. These details will be presented separately later in separate sections.

select element allows you to configure many attributes to configure the details of how each statement.

<select
  id="selectPerson" parameterType="int" parameterMap="deprecated" resultType="hashmap" resultMap="personResultMap" flushCache="false" useCache="true" timeout="10" fetchSize="256" statementType="PREPARED" resultSetType="FORWARD_ONLY">
Select &#x5143;&#x7d20;&#x7684;&#x5c5e;&#x6027;
Attributes description
id In the namespace unique identifier that can be used to reference this statement.
parameterType It will be passed in this statement parameters like the fully qualified name or alias . This attribute is optional, as may be inferred from the type of processor MyBatis (the TypeHandler) concrete statement passed parameters, the default value is not set (unset).
parameterMap This is a reference method has been discarded outside the parameterMap. Use inline parameter mappings and parameterType property.
resultType The fully qualified name or alias returned from this statement of the expected type. Note that if the return is a collection that should be set to the type collection contains, rather than the collection itself. You can use resultType or resultMap, but not both.
resultMap ResultMap named external references . MyBatis mapping result set is the most powerful feature, if you thoroughly understand it, in many cases complex mappings can be solved. You can use resultMap or resultType, but not both.
flushCache After it is set to true, as long as the statement is called, will result in the local cache and secondary cache is cleared, the default value: false.
useCache After it is set to true, will result of this statement results are cached up secondary cache , default: to select the element to true.
timeout This setting is before throwing an exception, the driver waits for the request to return the database results in seconds . The default value is not set (the unset) (dependent on drive).
fetchSize This is a hint to the driver, the driver attempts to make the results of each row and the set values ​​of equal quantities of return. The default value is not set (the unset) (dependent on drive).
statementType STATEMENT, PREPARED or CALLABLE one . This will make MyBatis were used Statement, PreparedStatement or CallableStatement, default value: PREPARED.
resultSetType FORWARD_ONLY, SCROLL_SENSITIVE, SCROLL_INSENSITIVE or the DEFAULT (equivalent to the unset) one of a default value of unset (dependent on drive).
databaseId If the configuration database vendor identification (databaseIdProvider), MyBatis will load all without databaseId or match the current databaseId statement; if statement with or without have, no band will be ignored.
resultOrdered This setting only for the result of the nested select statement applies: If true, is the assumption that contain nested result set or group, so as to return the results of a main line, they will not happen to have a reference in front of the result set Happening. This makes nested at the time of acquisition of the result set does not lead to memory is not enough. Default value: false .
resultSets This setting case applies only to multi-result set . It will list the result set returned after each statement is executed and the result set to a name, the name is separated by commas.
2、
2. Return to top
 
3. Back to top
 
4. Top
 
5. Top
1、
2、
 
6. Back to top
 
warn Author: ylbtech
Source: http://ylbtech.cnblogs.com/
This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise We reserve the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/storebook/p/10979953.html