网站打开是404,做挂网站,优秀 网站设计 蓝色,正规网站建设服务目录 JSONObject的使用 TreeUtil的使用
EagleMap使用
安装
application.yml配置 springboot导入依赖
配置信息
简单使用
如果想获取这个json字符串里面的distance的值 BeanUtil拷贝注意 JSONObject的使用
假如我现在要处理这样的json数据 可以直接使用JSONUtil.parseObj…目录 JSONObject的使用 TreeUtil的使用
EagleMap使用
安装
application.yml配置 springboot导入依赖
配置信息
简单使用
如果想获取这个json字符串里面的distance的值 BeanUtil拷贝注意 JSONObject的使用
假如我现在要处理这样的json数据 可以直接使用JSONUtil.parseObj()方法将其解析成JSONObject对象
JSONObject jsonObject JSONUtil.parseObj(msg); 现在要获取里面的值因为type是字符串类型所以使用getStr(key)方法 String type jsonObject.getStr(type);
String operation jsonObject.getStr(operation); 获取数组类型的值使用getJSONArray()方法然后获取下标为0的值并且强转为JSONObject类型。
JSONObject content (JSONObject) jsonObject.getJSONArray(content).getObj(0);
获取Long类型的值使用getLong()方法会自动把字符串类型转换成Long类型
Long parentId content.getLong(parentId);
获取boolean类型的值使用getBool()方法
content.getBool(status)
获取int类型的值使用getInt方法
content.getInt(managerId) TreeUtil的使用
在处理业务时我们会碰到要把一个集合数据将其转换成树状结构返回给前端hutool工具类提供了一个TreeUtil工具类可以帮我们很快的实现这个业务
参考文档
树结构工具-TreeUtil 示例
在一个类里要有parentId成员变量代指父亲id,一般第一层的父id都规定为0 使用
GetMapping(tree)public String findAllTree() throws JsonProcessingException {// TODO day05 查询机构树// 查询全部机构数据 如果为空返回空字符串ListOrganDTO organDTOS this.organService.findAll(null);// 如果不为空构造树结构 tips: 使用TreeUtil构建if(CollUtil.isNotEmpty(organDTOS)){//让0作为第一层的父idListTreeLong trees TreeUtil.build(organDTOS, 0L, (organDTO, tree) - {//这三个值一定要设置tree.setId(organDTO.getId());tree.setParentId(organDTO.getParentId());tree.setName(organDTO.getName());//批量把成员变量导入tree.putAll(BeanUtil.beanToMap(organDTO));});// 通过jackson将数据节点转为json字符串 objectMapper.writeValueAsStringreturn objectMapper.writeValueAsString(trees);//如果使用JSONUtil序列化就会缺少值为空的成员变量}return ;} 刚开始去数据库查询所有数据时没有分层关系 (organDTO, tree) - {//这三个值一定要设置tree.setId(organDTO.getId());tree.setParentId(organDTO.getParentId());tree.setName(organDTO.getName());//批量把成员变量导入tree.putAll(BeanUtil.beanToMap(organDTO));} lambda表达式organDto代指集合的每一个数据tree是树型数据泛型是id类型为Longid,parentId,name一定要设置然后通过putAll方法把organDto的成员变量都赋值给树形数据 // 通过jackson将数据节点转为json字符串 objectMapper.writeValueAsStringreturn objectMapper.writeValueAsString(trees);//如果使用JSONUtil序列化就会缺少值为空的成员变量 这里使用jackson的ObjectMapper来json序列化因为JOSNUtil的json序列化不会序列化值为空的成员变量 结果
tree树形数据会自动添加children成员变量 如果不使用这个工具类就需要在OrganDto类下添加成员变量
ListOrganDTOchildren;
然后使用递归 private ListOrganDTOgetTree(ListOrganDTOorganDTOS,Long pid){ListOrganDTOtreenew ArrayList();for (OrganDTO organDTO : organDTOS) {OrganDTO node;if(ObjectUtil.equals(organDTO.getParentId(),pid)){node new OrganDTO();BeanUtil.copyProperties(organDTO,node);node.setChildren(getTree(organDTOs,organDTO.getParentId()))}tree.add(node);}return tree;}
EagleMap使用
文档
EagleMap - 地图服务中台 黑马程序员·研究院
安装 #拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/itheima/eagle-map-server:latestdocker create --name eagle-map-server \
-p 8484:8484 \
-v itcast/eaglemap/app/application.yml:/app/eagle-map-server/conf/application.yml \
-v itcast/eaglemap/app/logs:/app/eagle-map-server/logs \
registry.cn-hangzhou.aliyuncs.com/itheima/eagle-map-server:latest#以上命令指定了端口号、配置文件、日志等信息docker start eagle-map-server application.yml配置
server:port: 8484 #RESTful服务端口
spring:
# datasource: #数据库的配置
# driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://172.17.2.135:3306/eaglemap?useUnicodetruecharacterEncodingutf8autoReconnecttrueallowMultiQueriestrueuseSSLfalse
# username: root
# password: root123
eagle:#服务模式可选参数BASE、COMPLETE默认BASE#BASE模式中无需配置数据库只保留基础的地图服务service-mode: BASE#默认策略可选参数BAIDU、AMAP、NONE默认NONE#如果指定了默认策略在接口中不指定服务商时才用的策略如果指定NONE有系统来决定default-provider-strategy: NONEbaidu-web-api: https://api.map.baidu.com #百度地图web api服务地址baidu-ying-yan-api: http://yingyan.baidu.com #百度地图鹰眼服务地址amap-web-api: https://restapi.amap.com #高德地图web api服务地址amap-ts-api: https://tsapi.amap.com #高德地图猎鹰服务地址admin: #可视化管理系统的配置user: eagle #用户名password: b09315ea09c6d3b5680094257f1f70e4 #密码eaglemd5加密后#RSA的私钥#RSA的公钥token-time: 24 #token有效期单位小时timeout: 30000 #请求超时时间单位毫秒trace-image: #轨迹缩略图scale: 0.9 #缩放比默认0.9background: #FFFFFF #背景颜色trace-color: #6699FF #轨迹颜色stroke-width: 3 #画笔宽度width: 300 #生成图片的宽度height: 300 #生成图片的高度
# baidu: #百度相关的配置
# enable: false #是否启用
# name: 百度地图 #服务商的名称
# server: #服务端账号的配置
# id: xxxxx
# name: xxxxx
# ak: xxxxx
# type: xxxxx
# browser: #浏览器端账号的配置
# id: xxxxx
# name: xxxxx
# ak: xxxxx
# type: xxxxx
# trace-servers: #百度地图中的轨迹服务
# - id: xxxxx
# name: xxxxx
# type: xxxxx
# date: xxxxx
# - id: xxxxx
# name: xxxxx
# type: xxxxx
# date: xxxxxamap: #高德相关的配置enable: true #是否启用name: 高德地图 #服务商的名称server: #服务端账号的配置name: EagleMap-Serverak: 85db5737cb07bd69fd79c47db37edtype: Web服务browser: #浏览器端账号的配置name: EagleMap-JSak: 0249fa505ac60236af082df54413266sk: 52decdd5151bac3021fa6736979258type: Web端amap: #高德相关的配置 enable: true #是否启用 name: 高德地图 #服务商的名称 server: #服务端账号的配置 name: EagleMap-Server ak: 85db5737cb07bd69fd79c47db37ed type: Web服务 browser: #浏览器端账号的配置 name: EagleMap-JS ak: 0249fa505ac60236af082df54413266 sk: 52decdd5151bac3021fa6736979258 type: Web端 这里配置了高德地图ak值需要我们自己去申请 我的应用 | 高德控制台 然后创建新的应用创建完成添加key 这里分别创建两个key,一个是服务端一个是web端 创建完成 springboot导入依赖
dependencygroupIdcom.itheima.em/groupIdartifactIdeaglemap-spring-boot-starter/artifactIdversion1.0/version/dependency
配置信息
eagle:host: 192.168.150.101 #EagleMap服务地址port: 8484 #EagleMap服务端口timeout: 20000 #http请求的超时时间
简单使用
SpringBootTest
public class Test2 {ResourceEagleMapTemplate eagleMapTemplate;Testpublic void test01(){//详细地址转换坐标String address 北京大学;GeoResult geoResult this.eagleMapTemplate.opsForBase().geoCode(ProviderEnum.AMAP, address, null);System.out.println(geoResult);} Testpublic void driving() {//驾车路线规划Coordinate origin new Coordinate(116.34411597643727, 40.06061915065967);Coordinate destination new Coordinate(116.398704, 39.907539);String result this.eagleMapTemplate.opsForDirection().driving(ProviderEnum.AMAP, origin, destination);System.out.println(result);} 一共有三条路线
如果想获取这个json字符串里面的distance的值 一般方法 JSONObejct jsonObject JSONUtil.parseObject(msg); JSONObject routejsonObject.getObj(route); JSONObject pathroute.getJSONArray(path).getObj(0); Long distancepath.getLong(distance); 特殊方法 JSONObejct jsonObject JSONUtil.parseObject(msg); Long distanceConvert.toLong(jsonObject.getByPath(route.paths[0].distance));//只要我们规定要要取到值的路径hutool工具类会直接帮我们获取到值 BeanUtil拷贝注意
在将transportLine的成员变量的值拷贝给transportLineDate数据时不会把transportLine值为空的成员变量进行拷贝也不会把值覆盖到transportLineDate原来的typestartOrganIdstartOrganNameendOrganIdendOrganName
//拷贝数据忽略null值以及不能修改的字段BeanUtil.copyProperties(transportLine, transportLineData, CopyOptions.create().setIgnoreNullValue(true).setIgnoreProperties(type, startOrganId, startOrganName, endOrganId, endOrganName));