查询语句是使用 MyBatis 时最常用的元素之一。 select 元素有很多属性允许你配置,来决定每条语句的作用细节。 | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
简单的查询 | ||||||||||||||||||||||||||||
<select id="selectPerson" parameterType="int" resultType="hashmap"> SELECT * FROM PERSON WHERE ID = #{id} </select> | ||||||||||||||||||||||||||||
这个语句被称作 selectPerson, 使用一个 int (或 Integer) 类型的参数, 并返回一个 HashMap 类型的对象,其中的键是列名,值是列对应的值。 | ||||||||||||||||||||||||||||
就像这样: | ||||||||||||||||||||||||||||
String selectPerson = "SELECT * FROM PERSON WHERE ID=?"; PreparedStatement ps = conn.prepareStatement(selectPerson); ps.setInt(1, id); | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
可配置的属性 | ||||||||||||||||||||||||||||
<select id="selectPerson" parameterType="int" parameterMap="deprecated" resultType="hashmap" resultMap="personResultMap" flushCache="false" useCache="true" timeout="10000" fetchSize="256" statementType="PREPARED" resultSetType="FORWARD_ONLY"> | ||||||||||||||||||||||||||||
|