select元素配置细节如下
属性 | 描述 | 取值 | 默认 |
id | 在这个模式下唯一的标识符,可被其它语句引用 | ||
parameterType | 传给此语句的参数的完整类名或别名 | ||
resultType | 语句返回值类型的整类名或别名。注意,如果是集合,那么这里填写的是集合的项的整类名或别名,而不是集合本身的类名。(resultType 与resultMap 不能并用) | ||
resultMap | 引用的外部resultMap 名。结果集映射是MyBatis 中最强大的特性。许多复杂的映射都可以轻松解决。(resultType 与resultMap 不能并用) | ||
flushCache | 如果设为true,则会在每次语句调用的时候就会清空缓存。select 语句默认设为false | true|false | false |
useCache | 如果设为true,则语句的结果集将被缓存。select 语句默认设为false true|false false timeout 设置驱动器在抛出异常前等待回应的最长时间,默认为不设值,由驱动器自己决定 |
true|false | false |
timeout | 设置驱动器在抛出异常前等待回应的最长时间,默认为不设值,由驱动器自己决定 | 正整数 | 未设置 |
fetchSize | 设置一个值后,驱动器会在结果集数目达到此数值后,激发返回,默认为不设值,由驱动器自己决定 | 正整数 | 驱动器决定 |
statementType | statement,preparedstatement,callablestatement。 预准备语句、可调用语句 |
STATEMENT PREPARED CALLABLE |
PREPARED |
resultSetType | forward_only,scroll_sensitive,scroll_insensitive 只转发,滚动敏感,不区分大小写的滚动 |
FORWARD_ONLY SCROLL_SENSITIVE SCROLL_INSENSITIVE |
驱动器决定 |
示例:
- <resultMap id="detailResultMap" type="com.myapp.domain.Blog">
- <id column="id" property="id" jdbcType="INTEGER"/>
- <result column="author_id" property="authorId" jdbcType="INTEGER" />
- <result column="title" property="title" jdbcType="VARCHAR" />
- <collection property="posts" ofType="com.myapp.domain.Post">
- <id column="postId" property="id"></id>
- <result column="blog_id" property="blogId"></result>
- <result column="subject" property="subject"/>
- </collection>
- </resultMap>
- <select id="getBlogs" resultMap="detailResultMap" parameterType="com.myapp.domain.Author">
- select b.title,b.id,b.author_id,c.id as postId,c.subject from Blog b
- left join Post c on (b.id=c.blog_id and b.author_id=c.author_id)
- where b.author_id=#{id}
- </select>