一些有的没得小知识

1. 空间函数 st_distance_sphere / st_distance 计算距离

st_distance在mysql5.6+加入的;st_distance_sphere 在mysql5.7+加入的

一些有的没得小知识_第1张图片

通过经纬度查询距目标(113.8064049, 22.7300434)最近的五个地点,详情可见链接:参考链接

SELECT city,distance FROM (SELECT *, ST_DISTANCE_SPHERE(point (113.8064049, 22.7300434),point(longitude,latitude)) AS DISTANCE FROM data_point) A
ORDER BY distance ASC LIMIT 5

2. Stream流将List转Map

List<ContentVO> vos = contentService.findContentServicePage(vo);

Map<String, List<ContentVO>> listMap = vos.stream().collect(Collectors.groupingBy(ContentVO::getName));

Map<String, ContentVO> voMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, Function.identity()));
// key 冲突时后者进行覆盖
Map<String, ContentVO> contentVOMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, Function.identity(), (oldValue, newValue) -> newValue));

Map<String, String> stringMap = vos.stream().collect(Collectors.toMap(ContentVO::getName, ContentVO::getSubTitle));
Map<String, String> collect = vos.stream().collect(Collectors.toMap(ContentVO::getName, ContentVO::getSubTitle, (oldValue, newValue) -> newValue));

你可能感兴趣的:(SQL,mysql)