mybaits 注解 返回Map

 第一种 、以Map方式返回

mapper接口如下

@MapKey("sn")//应该是bean属性,用到get方法
@ResultType(LbsDTO.class)设置value bean.class
@Select("select * from LBS where elaId = #{elaId}")
Map selectMapByElaId(int elaId);

 结果:

mybaits 注解 返回Map_第1张图片

第二种、以Map>形式返回

mapper接口如下

@MapKey("id")//设置key
@Select("select * from USER where eId = #{eId}")
Map> selectMapByEId(int eId);

 结果

​​​​{154711925668={updatedTime=1547119267023, swVersion=001, mac=52:54:00:FC:7D:D2, hwVersion=01, spaceId=3, onTime=1547119256702, elaId=1, x=11.55, y=0.0, createdTime=1547119267023, z=-1.29, id=1, sn=154711925668, status=1}, 
154712370184={updatedTime=1547123704841, swVersion=001, onTime=1547123701875, elaId=1, createdTime=1547123704841, id=20, sn=154712370184, mac=52:54:00:CF:50:6F, hwVersion=01, status=1}}

第三种、以List> 形式返回

mapper接口如下


	@Select("select * from LBS where elaId = #{elaId}")
	List> selectMapListByElaId(int elaId);

结果:

[{updatedTime=1547119267023, swVersion=001, mac=52:54:00:FC:7D:D2, hwVersion=01, spaceId=3, onTime=1547119256702, elaId=1, x=11.55, y=0.0, createdTime=1547119267023, z=-1.29, id=1, sn=154711925668, status=1},
{updatedTime=1547123703844, swVersion=001, mac=52:54:00:03:21:12, hwVersion=01, spaceId=5, onTime=1547123701872, elaId=1, x=10.0, y=0.0, createdTime=1547123703844, z=0.0, id=2, sn=154712370184, status=1}, 
{updatedTime=1547123703929, swVersion=001, mac=52:54:00:00:D9:53, hwVersion=01, onTime=1547123701872, elaId=1, x=0.0, y=0.0, createdTime=1547123703929, z=0.0, id=3, sn=154712370184, status=1}]

注意:前两种外层Key重复会被覆盖,所以前两种查到2条数据,第三种查到3条。

 

你可能感兴趣的:(web)