您的位置:首页 > 其它

Mybatis知识点备忘

2017-06-01 20:15 288 查看
1.在Mapper中,如果需要生成嵌套的复杂对象,可以使用ResultMap,ResultMap中拥有这些属性

<!-- Very Complex Result Map -->
<resultMap id="detailedBlogResultMap" type="Blog">
<constructor>
<idArg column="blog_id" javaType="int"/>
</constructor>
<result property="title" column="blog_title"/>
<association property="author" javaType="Author">
<id property="id" column="author_id"/>
<result property="username" column="author_username"/>
<result property="password" column="author_password"/>
<result property="email" column="author_email"/>
<result property="bio" column="author_bio"/>
<result property="favouriteSection" column="author_favourite_section"/>
</association>
<collection property="posts" ofType="Post">
<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>
<association property="author" javaType="Author"/>
<collection property="comments" ofType="Comment">
<id property="id" column="comment_id"/>
</collection>
<collection property="tags" ofType="Tag" >
<id property="id" column="tag_id"/>
</collection>
<discriminator javaType="int" column="draft">
<case value="1" resultType="DraftPost"/>
</discriminator>
</collection>
</resultMap>


constructor:类在实例化时,用来注入结果到构造方法中

idArg:ID参数;标记结果作为ID可以帮助提高整体效能

arg:注入到构造方法的一个普通结果

id:一个ID结果;标记结果作为ID可以帮助提高整体效能

result:注入到字段或JavaBean属性的普通结果

association:一个复杂的类型关联;许多结果将包成这种类型(复杂自定义类型嵌套时常用)

嵌入结果映射结果映射自身的关联,或者参考一个

collection:复杂类型的集

嵌入结果映射结果映射自身的集,或者参考一个

discriminator:使用结果值来决定使用哪个结果映射

case:基于某些值的结果映射

嵌入结果映射这种情形结果也映射它本身,因此可以包含很多相同的元素,或者它可以参照一个外部的结果映射。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis