zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    有关android UI 线程
    lang3日期工具类底层源码解析
    JSON业务模型拆解技巧
    math3底层源码解决多元方程组
    关于日期解析Scala语言
    maven仓库支持cdh版本配置
    kudu数据库个人简单的总结
    json数据入库kafka
    json数据写入hbase
    一只鸟的故事
  • 原文地址:https://www.cnblogs.com/panxuejun/p/6127066.html
Copyright © 2011-2022 走看看