当前位置: 首页 > news >正文

httpclient工具类(支持泛型转换)

1、网上搜到的httpclient工具类的问题:

1.1、如下图我们都能够发现这种封装的问题:

  • 代码繁杂、充斥了很多重复性代码
  • 返回值单一,无法拿到对应的Java Bean对象及List对象集合
  • 实际场景中会对接大量第三方的OPEN API,下述方法的扩展性差

在这里插入图片描述

1.2、简洁调用方式演示

本文基于上述问题,通过设计模式、泛型、JSON工具类的方式进行了封装,得到了下述更方便、更简洁的http请求调用方式

Entity params = new Entity();
params.setUrl("/common/postJson");Map<String, Object> map = new HashMap<>();
map.put("userId", "13277887788");
map.put("companyId", "87037827534cf");
params.setParams(map);// 返回对象集合
List<AppEntity> appEntity = thirdHttpProcessorFactory.doGetReturnList(ThirdSystemEnum.ION, params, AppEntity.class);
// 返回String类型
String result = thirdHttpProcessorFactory.doGetReturnBean(ThirdSystemEnum.ION, params, String.class);
// 返回指定的对象
AppEntity appEntity = thirdHttpProcessorFactory.doGetReturnBean(ThirdSystemEnum.ION, params, AppEntity.class);

1.3、 目录结构

在这里插入图片描述

2、引入的maven仓库

 <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.14.2</version>
</dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.16</version>
</dependency>
  • ThirdHttpProcessorFactory:存储不同三方平台的处理期
  • ThirdHttpProcessor:定义通用的接口
  • AbstractThirdHttpProcessor:定义公共的处理逻辑
  • IonHttpProcessor:定义各对接平台的差异性逻辑
  • AppEntity:返回值
  • Entity:入参
  • ThirdSystemEnum:定义三方平台的枚举

3、代码实现

3.1、获取不同第三方处理器的工厂ThirdHttpProcessorFactory

package com.ionrocking.platform.tripartite;import com.ionrocking.common.core.exception.ServiceException;
import com.ionrocking.platform.tripartite.entity.Entity;
import com.ionrocking.platform.tripartite.enums.ThirdSystemEnum;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** @author ke* Created by on  2023-10-27 15:23*/
@Component
@Accessors(chain = true)
public class ThirdHttpProcessorFactory {@Autowiredprivate List<ThirdHttpProcessor> thirdHttpProcessors;private Map<String, ThirdHttpProcessor> thirdHttpProcessorMap;@PostConstructpublic void init() {if (CollectionUtils.isEmpty(thirdHttpProcessors)) {return;}thirdHttpProcessorMap = new HashMap<>(8);for (ThirdHttpProcessor processor : thirdHttpProcessors) {thirdHttpProcessorMap.put(processor.getType().getCode(), processor);}}private ThirdHttpProcessor getThirdHttpProcessor(String type) {ThirdSystemEnum thirdSystemEnum = ThirdSystemEnum.getByCode(type);if (null == thirdSystemEnum) {throw new ServiceException("三方OpenApi尚未配置,无法进行请求");}return thirdHttpProcessorMap.get(type);}/*** http get请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return T              返回数据对象* @throws Exception 业务执行异常*/public <T> T doGetReturnBean(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doGetReturnBean(entity, tClass);}/*** http post请求,入参支持application/x-www-form-urlencoded 请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return T              返回数据对象* @throws Exception 业务执行异常*/public <T> T doPostReturnBean(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doPostReturnBean(entity, tClass);}/*** http post请求,入参支持application/json请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return T              返回数据对象* @throws Exception 业务执行异常*/public <T> T doPostJsonReturnBean(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doPostJsonReturnBean(entity, tClass);}/*** http get请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return List<T>        返回数据集合* @throws Exception 业务执行异常*/public <T> List<T> doGetReturnList(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doGetReturnList(entity, tClass);}/*** http post请求,入参支持application/x-www-form-urlencoded 请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return List<T>        返回数据集合* @throws Exception 业务执行异常*/public <T> List<T> doPostReturnList(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doPostReturnList(entity, tClass);}/*** http post请求,入参支持application/json请求** @param thirdSystemEnum 三方系统类型枚举* @param entity          参数* @param tClass          返回参数类型* @return List<T>        返回数据集合* @throws Exception 业务执行异常*/public <T> List<T> doPostJsonReturnList(ThirdSystemEnum thirdSystemEnum, Entity entity, Class<T> tClass) throws Exception {return getThirdHttpProcessor(thirdSystemEnum.getCode()).doPostJsonReturnList(entity, tClass);}}

3.2、http请求处理的接口ThirdHttpProcessor

/*** Dans.com Inc.* Copyright (c) 2011-2020 All Rights Reserved*/
package com.ionrocking.platform.tripartite;import com.ionrocking.platform.tripartite.entity.Entity;
import com.ionrocking.platform.tripartite.enums.ThirdSystemEnum;import java.util.List;/*** 追踪事件处理器** @author ke* Created by on  2023-06-20 15:23*/
public interface ThirdHttpProcessor {/*** 业务执行** @param entity* @param tClass* @return T* @throws Exception 业务执行异常*/<T> T doGetReturnBean(Entity entity, Class<T> tClass) throws Exception;/*** 业务执行** @param entity* @param tClass* @return* @throws Exception 业务执行异常*/<T> T doPostReturnBean(Entity entity, Class<T> tClass) throws Exception;/*** 业务执行** @param entity* @param tClass* @return* @throws Exception 业务执行异常*/<T> T doPostJsonReturnBean(Entity entity, Class<T> tClass) throws Exception;/*** 业务执行** @param entity* @param tClass* @return T* @throws Exception 业务执行异常*/<T> List<T> doGetReturnList(Entity entity, Class<T> tClass) throws Exception;/*** 业务执行** @param entity* @param tClass* @return* @throws Exception 业务执行异常*/<T> List<T> doPostReturnList(Entity entity, Class<T> tClass) throws Exception;/*** 业务执行** @param entity* @param tClass* @return* @throws Exception 业务执行异常*/<T> List<T> doPostJsonReturnList(Entity entity, Class<T> tClass) throws Exception;/*** 获取事件类型** @return*/ThirdSystemEnum getType();
}

3.3、通用逻辑处理的抽象类AbstractThirdHttpProcessor

  • 如在通过http client发起HTTP请求时,除了请求头requestHeader、请求入参requestBody不同,其他逻辑都是一样的,则可以进行公共代码的抽取
  • 如果存在特殊的逻辑处理,则可以在子类中重写父类的方法
package com.ionrocking.platform.tripartite;import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ionrocking.common.core.exception.ServiceException;
import com.ionrocking.platform.config.SysNacosConfig;
import com.ionrocking.platform.tripartite.entity.Entity;
import com.ionrocking.platform.tripartite.entity.IonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;/*** @author ke* @Date 2023/10/27*/
@Slf4j
@Component
public abstract class AbstractThirdHttpProcessor implements ThirdHttpProcessor {@Overridepublic <T> List<T> doGetReturnList(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createGet(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).form(requestBody).execute().body();return toList(result, tClass);}@Overridepublic <T> List<T> doPostReturnList(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createPost(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).form(requestBody).execute().body();return toList(result, tClass);}@Overridepublic <T> List<T> doPostJsonReturnList(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createPost(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).body(JSONUtil.toJsonStr(requestBody)).execute().body();return toList(result, tClass);}public <T> T toBean(String result, Class<T> tClass) throws Exception {ObjectMapper objectMapper = new ObjectMapper();IonResponse<Object> response = JSONUtil.toBean(result, IonResponse.class);if (CODE != response.getCode()) {throw new ServiceException(response.getMsg());}if (null == response.getData()) {return null;}return objectMapper.readValue(response.getData().toString(), tClass);}public <T> List<T> toList(String result, Class<T> tClass) throws JsonProcessingException {List<T> data = new ArrayList<>();IonResponse<List<Object>> response = JSONUtil.toBean(result, IonResponse.class);if (CODE != response.getCode()) {throw new ServiceException(response.getMsg());}if (CollUtil.isEmpty(response.getData())) {return null;}for (Object o : response.getData()) {ObjectMapper objectMapper = new ObjectMapper();data.add(objectMapper.readValue(o.toString(), tClass));}return data;}@Resourceprotected SysNacosConfig sysNacosConfig;protected static final int CODE = 200;@Overridepublic <T> T doGetReturnBean(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createGet(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).form(requestBody).execute().body();return toBean(result, tClass);}/*** 执行** @return*/@Overridepublic <T> T doPostReturnBean(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createPost(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).form(requestBody).execute().body();return toBean(result, tClass);}@Overridepublic <T> T doPostJsonReturnBean(Entity entity, Class<T> tClass) throws Exception {// 构造请求头Map<String, String> requestHead = constructRequestHead(entity);// 构造请求数据Map<String, Object> requestBody = constructRequestBody(entity);String result = HttpUtil.createPost(sysNacosConfig.getIonRequestUrl() + entity.getUrl()).addHeaders(requestHead).body(JSONUtil.toJsonStr(requestBody)).execute().body();return toBean(result, tClass);}/*** 构造请求头** @param entity* @return*/public abstract Map<String, String> constructRequestHead(Entity entity);/*** 构造请求体** @param entity* @return*/public Map<String, Object> constructRequestBody(Entity entity) {if (CharSequenceUtil.isBlank(entity.getUrl())) {throw new ServiceException("请求路径不能为空");}if (null == entity) {return null;}return entity.getParams();}}

3.4、第三方非通用逻辑处理类IonHttpProcessor

  • 比如此处对接的xx公司需要进行access_token获取及验证,然后将access_token放在请求头中
package com.ionrocking.platform.tripartite.impl;import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.ionrocking.platform.tripartite.AbstractThirdHttpProcessor;
import com.ionrocking.platform.tripartite.entity.Entity;
import com.ionrocking.platform.tripartite.entity.IonResponse;
import com.ionrocking.platform.tripartite.enums.ThirdSystemEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;import java.util.HashMap;
import java.util.Map;/*** @author ke* @Date 2023/10/27*/
@Slf4j
@Component
public class IonHttpProcessor extends AbstractThirdHttpProcessor {private String accessTokenUrl = "/token/getAccessToken";private static final String ACCESS_TOKEN_KEY = "access_token";@Overridepublic Map<String, String> constructRequestHead(Entity entity) {Map<String, String> header = new HashMap<>(2);Map<String, Object> params = new HashMap<>(4);params.put("appId", sysNacosConfig.getIonRequestAppId());params.put("appSecret", sysNacosConfig.getIonRequestAppSecret());String result = HttpUtil.get(sysNacosConfig.getIonRequestUrl() + accessTokenUrl, params);if (CharSequenceUtil.isEmpty(result)) {return null;}TypeReference<IonResponse<Map<String, Object>>> typeRef = new TypeReference<IonResponse<Map<String, Object>>>() {};IonResponse<Map<String, Object>> response = JSONUtil.toBean(result, typeRef, false);if (CODE == response.getCode() && null != response.getData()) {if (response.getData().containsKey(ACCESS_TOKEN_KEY)) {header.put(ACCESS_TOKEN_KEY, response.getData().get(ACCESS_TOKEN_KEY).toString());}}return header;}@Overridepublic ThirdSystemEnum getType() {return ThirdSystemEnum.ION;}
}

3.5、枚举类ThirdSystemEnum

  • 区分不同的平台,根据枚举获取不同的实现类
package com.ionrocking.platform.tripartite.enums;import org.apache.commons.lang3.StringUtils;/*** @author ke* @Date 2023/10/27*/
public enum ThirdSystemEnum {/*** XX科技公司*/ION("ion", "xx科技");private final String code;private final String name;public String getName() {return this.name;}public String getCode() {return this.code;}ThirdSystemEnum(String code, String name) {this.code = code;this.name = name;}public static ThirdSystemEnum getByCode(String code) {if (StringUtils.isEmpty(code)) {return null;}for (ThirdSystemEnum codeEnum : values()) {if (code.equals(codeEnum.getCode())) {return codeEnum;}}return null;}
}

3.6、第三方返回格式对象IonResponse

package com.ionrocking.platform.tripartite.entity;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.io.Serializable;/*** @author ke* @Date 2023/10/27*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class IonResponse<T> implements Serializable {private static final long serialVersionUID = -8741972144218822267L;private int code;/*** 消息*/private String msg;/*** 数据*/private T data;/*** 总记录数*/private long total;
}

3.7、处理器入参对象Entity

  • 此处定义请求的URL和请求的参数
package com.ionrocking.platform.tripartite.entity;import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;import java.io.Serializable;
import java.util.Map;/*** @author ke* @Date 2023/10/27*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Entity implements Serializable {private static final long serialVersionUID = -6083780287057302816L;private String url;/*** 参数*/private Map<String, Object> params;
}

3.8、第三方接口返回值对象AppEntity

package com.ionrocking.platform.tripartite.entity;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;import javax.validation.constraints.NotBlank;/*** @author ke* @Date 2023/10/26*/@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class AppEntity {private long id;private String appId;@NotBlank(message = "应用名称不能为空")private String appName;private String appSecret;private String accessToken;private Integer isFlag;
}

3.9、Nacos配置

  • Nacos中一般存放一些第三方的请求域名、鉴权的appId、appSecret等
tripartite-platform:ion:request:url: http://localhost:8080/api/appId: YodeqWwpappSecret: 87037827534cf848a570fae3c93a2469fa0262935af531dddfe7a52ae7f98f41
package com.ionrocking.platform.config;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;/*** nacos配置信息* @author ke* @Date 2023/9/20*/
@Component
public class SysNacosConfig {@Value("${upload.path}")private String uploadPath;@Value("${tripartite-platform.ion.request.url}")private String ionRequestUrl;@Value("${tripartite-platform.ion.request.appId}")private String ionRequestAppId;@Value("${tripartite-platform.ion.request.appSecret}")private String ionRequestAppSecret;public String getUploadPath() {return uploadPath;}public String getIonRequestUrl() {return ionRequestUrl;}public String getIonRequestAppId() {return ionRequestAppId;}public String getIonRequestAppSecret() {return ionRequestAppSecret;}
}

测试

@RestController
@RequestMapping("/test")
public class Test {@Resourceprivate SysNacosConfig sysNacosConfig;@Resourceprivate ThirdHttpProcessorFactory thirdHttpProcessorFactory;@ResponseBody@RequestMapping(value = "/get")public AjaxResult get() throws Exception extends BaseController  {Entity params = new Entity();params.setUrl("/common/get");String result = thirdHttpProcessorFactory.doGetReturnBean(ThirdSystemEnum.ION, params, String.class);return AjaxResult.success(result);}@ResponseBody@RequestMapping(value = "/list")public AjaxResult list() throws Exception {Entity params = new Entity();params.setUrl("/common/list");List<AppEntity> appEntity = thirdHttpProcessorFactory.doGetReturnList(ThirdSystemEnum.ION, params, AppEntity.class);return AjaxResult.success(appEntity);}@ResponseBody@RequestMapping(value = "/postJson")public AjaxResult postJson() throws Exception {Entity params = new Entity();params.setUrl("/common/postJson");Map<String, Object> map = new HashMap<>();map.put("appId", "YodeqWwp");map.put("appSecret", "87037827534cf848a570fae3c93a2469fa0262935af531dddfe7a52ae7f98f41");params.setParams(map);List<AppEntity> list = thirdHttpProcessorFactory.doPostJsonReturnList(ThirdSystemEnum.ION, params, AppEntity.class);return AjaxResult.success(list);}
}

相关文章:

httpclient工具类(支持泛型转换)

1、网上搜到的httpclient工具类的问题&#xff1a; 1.1、如下图我们都能够发现这种封装的问题&#xff1a; 代码繁杂、充斥了很多重复性代码返回值单一&#xff0c;无法拿到对应的Java Bean对象及List对象集合实际场景中会对接大量第三方的OPEN API&#xff0c;下述方法的扩展…...

【华为OD题库-003】最佳植树距离-Java

题目 小明在直线的公路上种树&#xff0c;现在给定可以种树的坑位的数星和位置&#xff0c;以及需要种多少棵树苗&#xff0c;问树苗之间的最小间距是多少时&#xff0c;可以保证种的最均匀&#xff08;两棵树苗之间的最小间距最大) 输入描述 输入三行: 第一行一个整数:坑位的数…...

Oracle(12)Managing Indexes

目录 目标&#xff1a; 一、基础知识 1、Classification ofindexes 索引的分类 2、B-Tree vs Bitmap 3、Creating Indexes: Guidelines 创建索引:准则 4、Offline Index Rebuild 脱机索引重建 5、RebuildingIndexes 重建索引 6、Online Index Rebuild 在线索引重建 7…...

DirectX3D 虚拟现实项目 三维物体的光照及着色(五个不同着色效果的旋转茶壶)

文章目录 任务要求原始代码CPP文件代码着色器文件代码 效果展示 任务要求 本篇文章是中国农业大学虚拟现实课程的一次作业内容&#xff0c;需要对五个茶壶模型使用不同的光照进行着色和渲染&#xff0c;然后旋转展示。 本人的代码也是在其他人的代码的基础上修改来的&#xf…...

【Verilog 教程】7.3 Verilog 串行 FIR 滤波器设计

串行 FIR 滤波器设计 设计说明 设计参数不变&#xff0c;与并行 FIR 滤波器参数一致。即&#xff0c;输入频率为 7.5 MHz 和 250 KHz 的正弦波混合信号&#xff0c;经过 FIR 滤波器后&#xff0c;高频信号 7.5MHz 被滤除&#xff0c;只保留 250KMHz 的信号。 输入频率&#x…...

用golang实现一个基于interface的多态示例,展示其使用场景和优劣性。

以下是一个简单的基于interface的多态示例&#xff0c;该示例展示了如何通过使用interface来实现多个不同类型的结构体的共同行为。具体示例如下&#xff1a; package mainimport "fmt"type Animal interface {Speak() string }type Dog struct {Name string }func …...

ArcGIS for Android 禁止地图旋转

ArcGIS for Android 禁止地图旋转 话不多说&#xff0c;直接上代码&#xff01;&#xff01;&#xff01; public class LoadMap extends AppCompatActivity {// 地图private MapView mapView;private ArcGISMap map;Overrideprotected void onCreate(Bundle savedInstanceSta…...

freertos静态创建任务

在开始前先有个小插曲&#xff0c;我的keil的自动补全代码功能使用不了&#xff0c;经过查找是因为之前装51把有的文件覆盖了&#xff0c;照这篇博客就可以解决。 然后之前那份代码我们是动态创建任务&#xff0c;先来说一下动态创建任务和静态创建任务的区别&#xff1a; Fre…...

VBA根据Excel内容快速创建PPT

示例需求&#xff1a;根据Excel中选中的单元格内容&#xff08;3列&#xff09;如下图所示&#xff0c;在已打卡的PowerPoint文件中创建页面。 新增PPT Slide页面使用第二个模板页面&#xff0c;其中包含两个文本占位符&#xff0c;和一个图片占位符。将Excel选中区域中前两列写…...

服务器操作系统有哪些

服务器操作系统有哪些 电脑想要运行就离不开操作系统&#xff0c;而服务器想要正常运行同样也离不开操作系统&#xff0c;那你知道服务器系统有哪些&#xff1f;服务器系统与电脑系统有什么区别&#xff1f;这些问题就由壹基比小鑫在下文中来告诉大家。 服务器系统有哪些&…...

泄漏检测与修复(LDAR)过程管控平台(销售出租)VOCs便携式总烃分析仪(销售出租)

LDAR是Leak Detection and Repair&#xff08;泄漏检测与修复&#xff09;的缩写&#xff0c;也是国际上较先进的化工废气检测技术。LDAR主要通过检测化工企业原料输送管道、泵、阀门、法兰等易产生易产生挥发性有机物&#xff08;简称VOCs&#xff09;泄漏的部位&#xff0c;并…...

VueX 模块化和namespace

当我们的项目很大的时候&#xff0c;VueX中的代码会越来越多&#xff0c;会有处理数据的&#xff0c;处理人员列表的&#xff0c;处理订单的... 如果我们将这些东西都写在一个state、actions和mutations中的话&#xff0c;就非常不方便后期的维护。 所以我们引入了VueX的模块…...

7-4 修理牧场 分数 15

#include<iostream> #include<queue> using namespace std; #define maxn 10005int main() {int n 0, data 0;cin >> n;//建小堆: //上调建堆中用greater: 父大子小 父子交换 小的上去 大的下去 priority_queue<int, vector<int>, greater<int…...

自定义element-ui plus 函数式调用,在API,js中直接使用全局组件

npm方式: npm install -D unplugin-vue-components unplugin-auto-import yarn 方式 : yarn add unplugin-vue-components; yarn add unplugin-auto-import; 使用官方的这个&#xff1a; vite.config.js中配置 plugins: [vue(),AutoImport({resolvers: [ElementPlusResolve…...

[LeetCode]-876.链表的中间结点-206.反转链表-21.合并两个有序链表-203.移除链表元素

目录 876.链表的中间结点 题目 思路 代码 206.反转链表 题目 思路 代码 21.合并两个有序链表 题目 思路 代码 203.移除链表元素 题目 思路 代码 876.链表的中间结点 876. 链表的中间结点 - 力扣&#xff08;LeetCode&#xff09;https://leetcode.cn/problems/mi…...

通过git多人协调开发

多人协调开发过程中的问题解决。 1.新建远程的仓库分支&#xff1b; 2.拉取线上代码&#xff0c;并在VScode中打开&#xff1b; 3 拉完之后&#xff0c;打开VScode之后的左下角显示的就是当前分支的名称&#xff0c;点击之后即可随意切换&#xff1b; 4 创建本地分支&#xff0…...

CentOS 7 通过 yum 安装 MariaDB(Mysql)

这一版取消了修改配置的操作&#xff0c;改成每次创建数据库时手动指定字符集编码&#xff1b;这一版取消了修改密码的操作&#xff0c;保留 MariaDB 使用无密码的情况&#xff0c;即密码是 ""。 安装步骤&#xff1a; 以下操作都以 root 用户进行操作 以下操作都以 …...

【Solidity】Remix在线环境及钱包申请

好久没有学习区块链方面的知识了&#xff0c;目前通过自学大致掌握了Fabric联盟链的搭建&#xff0c;链码编写、部署&#xff0c;api调用&#xff0c;可以独立开发出一些基于fabric的应用&#xff0c;感觉开发出去中心化的应用还是很有意思的&#xff0c;因为他与之前开发的ssm…...

ARFoundation系列讲解 - 92 涂鸦效果

--- 视频来源于网络,如有侵权必删 --- 案例中使用的软件版本 Unity2023.1.17.f1c1ARFoundtaion 5.1.0Apple ARKit XR Plugin 5.1.0 Google ARCore XR Plugin 5.1.0技术分析 我们可以实时检测用户手指触摸的屏幕位置,从触摸位置投射一条射线(Raycast),再射线命中的目标位置…...

立创eda专业版学习笔记(8)(运行模式)

以前没注意过这个问题&#xff0c;我有2台电脑&#xff0c;都能登录eda专业版&#xff0c;但是一台是全在线模式&#xff0c;另外一台是半离线模式&#xff0c;虽然是同一个账号&#xff0c;但是打开里面的工程会发现&#xff0c;两边的工程完全不同&#xff0c;因为一台的工程…...

【杂谈】-递归进化:人工智能的自我改进与监管挑战

递归进化&#xff1a;人工智能的自我改进与监管挑战 文章目录 递归进化&#xff1a;人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管&#xff1f;3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...

盘古信息PCB行业解决方案:以全域场景重构,激活智造新未来

一、破局&#xff1a;PCB行业的时代之问 在数字经济蓬勃发展的浪潮中&#xff0c;PCB&#xff08;印制电路板&#xff09;作为 “电子产品之母”&#xff0c;其重要性愈发凸显。随着 5G、人工智能等新兴技术的加速渗透&#xff0c;PCB行业面临着前所未有的挑战与机遇。产品迭代…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地

借阿里云中企出海大会的东风&#xff0c;以**「云启出海&#xff0c;智联未来&#xff5c;打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办&#xff0c;现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...

家政维修平台实战20:权限设计

目录 1 获取工人信息2 搭建工人入口3 权限判断总结 目前我们已经搭建好了基础的用户体系&#xff0c;主要是分成几个表&#xff0c;用户表我们是记录用户的基础信息&#xff0c;包括手机、昵称、头像。而工人和员工各有各的表。那么就有一个问题&#xff0c;不同的角色&#xf…...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求&#xff0c;由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面&#xff1a; &#x1f3db;️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限&#xff0c;形成层级清晰的管理网络&#xf…...

k8s业务程序联调工具-KtConnect

概述 原理 工具作用是建立了一个从本地到集群的单向VPN&#xff0c;根据VPN原理&#xff0c;打通两个内网必然需要借助一个公共中继节点&#xff0c;ktconnect工具巧妙的利用k8s原生的portforward能力&#xff0c;简化了建立连接的过程&#xff0c;apiserver间接起到了中继节…...

安宝特方案丨船舶智造的“AR+AI+作业标准化管理解决方案”(装配)

船舶制造装配管理现状&#xff1a;装配工作依赖人工经验&#xff0c;装配工人凭借长期实践积累的操作技巧完成零部件组装。企业通常制定了装配作业指导书&#xff0c;但在实际执行中&#xff0c;工人对指导书的理解和遵循程度参差不齐。 船舶装配过程中的挑战与需求 挑战 (1…...

Mysql中select查询语句的执行过程

目录 1、介绍 1.1、组件介绍 1.2、Sql执行顺序 2、执行流程 2.1. 连接与认证 2.2. 查询缓存 2.3. 语法解析&#xff08;Parser&#xff09; 2.4、执行sql 1. 预处理&#xff08;Preprocessor&#xff09; 2. 查询优化器&#xff08;Optimizer&#xff09; 3. 执行器…...

【C++进阶篇】智能指针

C内存管理终极指南&#xff1a;智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...

站群服务器的应用场景都有哪些?

站群服务器主要是为了多个网站的托管和管理所设计的&#xff0c;可以通过集中管理和高效资源的分配&#xff0c;来支持多个独立的网站同时运行&#xff0c;让每一个网站都可以分配到独立的IP地址&#xff0c;避免出现IP关联的风险&#xff0c;用户还可以通过控制面板进行管理功…...