MyBatis - 返回Map & List<Map>动态列数据集

总结: 两者在xml里面的resulttype均指定为hashmap,但interface里面,则一个是返回map,一个是返回list<map>

一、xml文件中的resultType都指定为HashMap

<select id="selectListMap" parameterType="java.lang.String" resultType="java.util.HashMap">

        select

               iid.username,age,password

        from sys_user

        where id=#{id,jdbcType=VARCHAR}

</select>



<select id="selectMap" parameterType="java.lang.String" resultType="java.util.HashMap">

       select

               iid.username,age,password

        from sys_user

       where id=#{id,jdbcType=VARCHAR}

</select>

二、修改interface增加两个接口方法

  •  List<Map<String,Object>> selectListMap(String id);
  •  Map<String,Object> selectMap(String id);

猜你喜欢

转载自blog.csdn.net/hutuyaoniexi/article/details/127687288