service层(interface)
Map<String,SysDict> mapByType(String type);
serviceImpl
@Override
@Cacheable(value = "SysDict_list", key = "'sysDict_list_ByType_' + #type")
public Map<String, SysDict> mapByType(String type) {
Map<String,SysDict> map = new HashMap<String,SysDict>();
List<SysDict> list = dictMapper.mapByType(type);
for(SysDict sysDict : list ){
map.put(sysDict.getValue(),sysDict);
}
return map;
}
controller
@GetMapping("mapByType")
@ResponseBody
public Map<String,SysDict> mapByType(String type){
return dictService.mapByType(type);
}
Mapper(interface)
List<SysDict> mapByType(@Param("type") String type);
Mapper(xml)
<select id="mapByType" resultType="com.hd.ucenter.model.entity.SysDict">
SELECT a.id,a.value,a.label, a.type,a.description,a.parent_id,a.sort as parentId,a.sort FROM sys_dict a
<where>
<if test="type != null">
AND a.type =#{type}
</if>
</where>
ORDER BY a.value
</select>