mybatis 查询返回List集合、map集合、List<Map>集合

2022-06-25 09:09:47

返回map类型

1. xml中
<select id="selectUser"  resultType="java.util.HashMap">  
</select>  

2.Dao接口中
Map<String,Object> selectUser();

这种方式SQL只能返回一行记录或者没有返回,如果返回多行记录,则程序报错。

返回List<String>类型

3. xml中
<select id="selectUser"  resultType="java.lang.String">  
</select>  

2.Dao接口中
List<String> selectUser();

这种方式可以返回多行记录,但是每行记录只有指定的一列数据。

返回List<Map>类型

1.xml中
<select id="selectUser"  resultType="java.util.HashMap">  
</select>  

2.Dao接口中
List<Map<String,Object>> selectUser ();

这种方式可以返回指定的多行多列的记录。

返回List<指定对象>类型

xml中:
<resultMap id="baseResult" type="com.XXX.BscntrUnitInfoResult(对应对象)">
		<result column="unit_id" property="unitId" jdbcType="INTEGER" (字段映射关系)/>
		<result column="unit_name" property="unitName"
			jdbcType="VARCHAR" />
		<result column="unit_type" property="unitType"
			jdbcType="INTEGER" />
		<result column="super_unit_id" property="superUnitId"
			jdbcType="INTEGER" />
		<result column="gis_start_x" property="gisStartX"
			jdbcType="FLOAT" />
		<result column="ext_top" property="extTop" jdbcType="DOUBLE" />
</resultMap>

<select id="getBscntrUnitInfoListByName" resultMap="baseResult">
		
</select>

Dao接口中:
public List<BscntrUnitInfoResult> getBscntrUnitInfoListByName();
  • 作者:彼岸-花已开
  • 原文链接:https://blog.csdn.net/szw906689771/article/details/115134689
    更新时间:2022-06-25 09:09:47