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

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

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