首页 > 代码库 > 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>就行了啊
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。