码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis返回list很智能很简答的,只需要配置resultmap进行类型转换,你dao方法直接写返回值list<对应的object>就行了啊

时间:2016-12-02 22:25:43      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:null   params   mail   open   tor   efi   select   ati   div   

mybatis返回list很智能很简答的,只需要配置resultmap进行类型转换,你dao方法直接写返回值list<对应的object>就行了啊 

dao方法    
public List<User> selectSimpleMulti(Map<String, Object> params){
        if(params == null){
            params = new HashMap<String, Object>();
        }
        
        return  dao.queryList(mapper+ "selectSimpleMulti", params);
    }

对应的mapper.xml配置sql语句

<resultMap id="BaseResultMap" type="User" extends="SimpleResultMap">
        <id property="uid" column="uid" />

        <result property="unionid" column="unionid"/>
        <result property="openid" column="openid"/>
        <result property="age" column="age"/>
        <result property="birthday" column="birthday"/>
        <result property="sex" column="sex"/>
        <result property="phone" column="phone"/>
        <result property="email" column="email"/>
        <result property="qq" column="qq"/>
        <result property="wechat" column="wechat"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="country" column="country"/>
        <result property="channel" column="channel"/>
        <result property="password" column="password"/>
        
        <!-- SimpleResultMap 中已经有
        <result property="nickname" column="nickname"/>
        <result property="headimgurl" column="headimgurl"/>
        <result property="appid" column="appid"/>
        <result property="password" column="password"/>
         -->
        <result property="backgroundimg" column="backgroundimg"/>
        <result property="description" column="description"/>
        <result property="createTime" column="create_time"/>
        
    </resultMap>
    
    <resultMap  id="SimpleResultMap" type="User">
        <id property="uid" column="uid" />
        <result property="nickname" column="nickname"/>
        <result property="headimgurl" column="headimgurl"/>
    </resultMap>

<select id="selectSimpleMulti" resultMap="SimpleResultMap">
select uid, nickname, headimgurl from tbl_user where
<trim prefixOverrides="and">
<if test="phone != null">
and phone = #{phone}
</if>
<if test="uidList != null and uid == null">
and uid in (
<foreach collection="uidList" item="item" separator=",">
#{item}
</foreach>
)
</if>
<if test="uidList == null and uid != null">
and uid = #{uid}
</if>
</trim>
</select>

 

mybatis返回list很智能很简答的,只需要配置resultmap进行类型转换,你dao方法直接写返回值list<对应的object>就行了啊

标签:null   params   mail   open   tor   efi   select   ati   div   

原文地址:http://www.cnblogs.com/panxuejun/p/6127066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!