首页 > 其他 > 详细

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

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

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>就行了啊

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!