A, select query
1.mybatis mapping, jdbc pretreatment
<select id="selectPerson" parameterType="int" resultType="hashmap"> SELECT * FROM PERSON WHERE ID = #{id} </select>
This is a simple select query sign # {id}, tell mybatis create a prepared statement parameters, through JDBC, this will be a parameter in SQL mosaic? Be identified, and reached a new prepared statement , like on the example below.
//JDBC代码,不是mubatis String selectContent = "SELECT * FROM PERSON WHERE ID=?"; PreparedStatement ps = conn.prepareStatement(selectContent); ps.setInt(1,id);
Such a lot of JDBC prepared in the underlying implementation, help us save time.
2.select label there will be many parameters, such as the following:
<select id="selectPerson" parameterType="int" parameterMap="deprecated" resultType="hashmap" resultMap="personResultMap" flushCache="false" useCache="true" timeout="10000" fetchSize="256" statementType="PREPARED" resultSetType="FORWARD_ONLY">
id: a unique identifier used to reference this statement.
parameterType: This statement incoming fully qualified name or alias parameters, this attribute is optional, can be inferred typeHandler statement parameters, the default value is unset.
resultType: Returns the desired type of fully qualified name or alias, if the time is set, the type is set, rather than the collection itself. resultMap and can not be used simultaneously resultType
resultMap: resultMap external use, defines a resultMap label, the label can be used elsewhere
flushCache: is true, as long as a call, the local cache and the secondary cache (cache) will be cleared, the default is false
useCache: set to true, the result will lead to this statement is the secondary cache
timeout: Before throwing an exception, waiting for the database to return results in seconds
fetchSize: This is an attempt to influence the results of each batch driver returns the number of rows and the set values are equal