Mybatis中多重复字段怎么映射?

SilenceSu 发布于 2013/12/18 16:24
阅读 4K+
收藏 0

 

系统使用mybatis、如果下面的sql怎么去写mapper。求教

select user.*,own.name,create.name from user 
left join emp as own on own.id=user.ownEmp_id
left join emp as create on create .id=user.createEmp_id



加载中
0
peanutmain
peanutmain

resultMap 才是Mybatis最强大的功能

<resultMap id="detailedBlogResultMap" type="Blog">
    <constructor>
        <idArg column="blog_id" javaType="int"/>
    </constructor>
    <result property="title" column="blog_title"/>
    <association property="author" column="blog_author_id" 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" column="post_author_id" javaType="Author"/>
    <collection property="comments" column="post_id" ofType=" Comment">
        <id property="id" column="comment_id"/>
        </collection>
        <collection property="tags" column="post_id" ofType=" Tag" >
            <id property="id" column="tag_id"/>
        </collection>
        <discriminator javaType="int" column="draft">
            <case value="1" resultType="DraftPost"/>
        </discriminator>
    </collection>
</resultMap>



0
心_行
心_行
要用到resultMap
心_行
心_行
先需要将相同名字的列要重命名
SilenceSu
SilenceSu
主要就是想问这个resultMap怎么配置。
0
double9
double9

列重命名不就行了

own.name as ownName,create.name as createName。

跟bean对应好就行

francis-x
francis-x
+10086
0
double9
double9
如果重命名的列还是跟bean不对应,就用 resultMap 做一下映射
SilenceSu
SilenceSu
这样的方法、要配置多个同样的resultMap. 个人感觉比较麻烦
返回顶部
顶部