Java中调用接口

一、微服务本地调用feign

Feign 是一个在 Java 平台上的声明式、模板化的 HTTP 客户端,它简化了使用 HTTP API 的过程。Feign 是 Netflix 开发的,旨在简化基于 HTTP 的 API 客户端开发。

1、特点

1.1:声明式 API 定义: 通过接口和注解的方式定义 API,使得 API 定义更加清晰和简洁。
1.2:集成 Ribbon: Feign 默认集成了 Ribbon 负载均衡器,可以轻松实现客户端的负载均衡。
1.3:集成 Hystrix: Feign 也可以集成 Hystrix,从而实现客户端的容错和断路器功能。
1.4:支持多种编码器和解码器: Feign 支持多种编码器和解码器,包括 JSON、XML 等。
1.5:支持动态 URL 和查询参数: 可以在接口方法中直接使用参数来构建 URL 和查询参数。

2、代码实例

2.1、添加maven支持
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.2、在服务启动类添加注解
@Slf4j//日志log
@SpringBootApplication//用于标识 Spring Boot 应用程序的注解
@EnableFeignClients//开启feign
@MapperScan("com.netrust.*.dao")//扫描包下的mapper
@EnableTransactionManagement//开启事务注解
public class BaseApplication {
    public static void main(String[] args) {
        SpringApplication.run(BaseApplication.class, args);
    }
}
2.3、编写feign类
@FeignClient(value = ServerNameConstants.SYSTEM_BASE, contextId = "room", configuration = FeignConfiguration.class)
public interface FeignApi {
    @PostMapping("/add")
    String addSysApi(@RequestBody FeignBO feignBO);
    @PutMapping("/edit")
    String editSysApi(@RequestBody FeignBO feignBO);
    @DeleteMapping("/delete")
    String deleteByIdSysApi(@RequestBody FeignDto feignDto);
    @GetMapping("/queryById")//@SpringQueryMap表示get可以用对象接收,不然就需要一个一个接收
    String queryById(@SpringQueryMap FeignDto feignDto);
    @RequestMapping(value = "file/personPhotoUpload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String personPhotoUpload(@RequestPart(value = "file") MultipartFile file,
                             @RequestParam(value = "moduleName") String moduleName,
                             @RequestParam(value = "functionName") String functionName,
                             @RequestParam(value = "needCompress") Boolean needCompress);
}
2.4、调用服务
@Resource
private FeignApi feignApi;
/**
* 通过主键查询单条数据
*/
@GetMapping("/feign/{id}")
@ApiOperation(value = "通过主键查询单条数据")
public ResultJson queryById( FeignDto feignDto, @PathVariable("id") Long id) {
   feignDto.setId(id);
   String s = feignApi.queryById(feignDto);
   return JSONObject.parseObject(s, ResultJson.class);
}
2.5、@FeignClient内部参数详解

2.5.1、value: 指定要调用的目标服务的服务名。可以是一个单独的服务名,也可以是多个服务名组成的数组。
2.5.2、url: 指定要调用的目标服务的URL地址,可以是一个完整的URL地址,也可以是占位符形式的URL地址。
2.5.3、path: 指定要调用的目标服务的基本路径,可以是一个字符串,也可以是一个占位符形式的字符串。
2.5.4、configuration: 指定要使用的Feign客户端配置类。可以自定义配置Feign客户端的行为。
2.5.5、decode404: 指定是否将404错误解码。默认情况下,Feign会将404错误解码为null值。
2.5.6、fallback: 指定一个回退类,当调用失败时,将调用回退类中的方法。回退类必须实现@FeignClient注解中的接口。
2.5.7、fallbackFactory: 指定一个回退工厂类,用于创建回退类的实例。回退工厂类必须实现FallbackFactory接口。
2.5.8、primary: 指定Feign客户端是否为首选客户端。如果设置为true,则优先使用该客户端。
2.5.9、qualifier: 指定Feign客户端的限定符。可以与@Autowired注解配合使用,用于指定要注入的Feign客户端实例。
2.5.10、name: 同value,指定要调用的目标服务的服务名。
2.5.11、contextId: 指定Feign客户端的上下文ID。用于区分不同的Feign客户端实例。
2.5.12、url: 指定要调用的目标服务的URL地址。

二、HttpClient

1、工具类

@Slf4j
public class HttpClientUtils {
    /**
     * 文件上传到第三方
     * @param url 网络地址
     * @param inputStream 文件流
     * @param headers 头文件(认证信息设置)
     * @param verification 是否需要验证
     * @return
     * @throws IOException
     */
    public static String uploadFile(String url, InputStream inputStream, Map<String, String> headers, boolean verification) throws IOException {
        HttpClient httpClient = verification ? HttpClients.createDefault() : wrapClient();
        HttpPost httpPost = new HttpPost(url);
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpPost.setConfig(requestConfig);

        if (headers != null) {
            headers.forEach((key, value) -> {
                httpPost.setHeader(key, value);
            });
        }
        //创建文件把流文件写入到字节内
        File file = File.createTempFile(UUID.randomUUID().toString(), ".jpg");
        FileOutputStream os = new FileOutputStream(file);

        int read = 0;
        byte[] buffer = new byte[1024];
        while ((read = inputStream.read(buffer, 0, 1024)) != -1) {
            os.write(buffer, 0, read);
        }
        inputStream.close();
        //发送邮件
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        FileBody fileBody = new FileBody(file, ContentType.MULTIPART_FORM_DATA);
        builder.addPart("file", fileBody);
        httpPost.setEntity(builder.build());

        HttpResponse response = httpClient.execute(httpPost);
        String httpEntityContent = getHttpEntityContent(response);
        httpPost.abort();
        return httpEntityContent;
    }

    /**
     * 封装HTTP POST方法
     *
     * @param verification TRUE为不跳过证书检测  FALSE为跳过证书检测
     * @param (如JSON串)
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */
    public static String post(String url, String body, Map<String, String> headers, boolean verification) throws ClientProtocolException, IOException {
        HttpClient httpClient = verification ? HttpClients.createDefault() : wrapClient();
        HttpPost httpPost = new HttpPost(url);
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpPost.setConfig(requestConfig);
        httpPost.setHeader("Content-Type", "application/json");
        if (headers != null) {
            headers.forEach((key, value) -> {
                httpPost.setHeader(key, value);
            });
        }
        if (body != null) {
            StringEntity s = new StringEntity(body, StandardCharsets.UTF_8);
            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            //设置参数到请求对象中
            httpPost.setEntity(s);
        }

        HttpResponse response = httpClient.execute(httpPost);
        String httpEntityContent = getHttpEntityContent(response);
        httpPost.abort();
        return httpEntityContent;
    }

    public static String put(String url, String body, Map<String, String> headers, boolean verification) throws ClientProtocolException, IOException {
        HttpClient httpClient = verification ? HttpClients.createDefault() : wrapClient();
        HttpPut httpPut = new HttpPut(url);
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpPut.setConfig(requestConfig);
        httpPut.setHeader(HTTP.CONTENT_TYPE, "application/json");
        if (headers != null) {
            headers.forEach((key, value) -> {
                httpPut.setHeader(key, value);
            });
        }
        if (body != null) {
            StringEntity s = new StringEntity(body, StandardCharsets.UTF_8);
            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            //设置参数到请求对象中
            httpPut.setEntity(s);
        }
        HttpResponse response = httpClient.execute(httpPut);
        String httpEntityContent = getHttpEntityContent(response);
        httpPut.abort();
        return httpEntityContent;
    }

    public static String delete(String url, String body, Map<String, String> headers, boolean verification) throws ClientProtocolException, IOException {
        HttpClient httpClient = verification ? HttpClients.createDefault() : wrapClient();
        HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(url);
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpDelete.setConfig(requestConfig);
        httpDelete.setHeader(HTTP.CONTENT_TYPE, "application/json");
        if (headers != null) {
            headers.forEach((key, value) -> {
                httpDelete.setHeader(key, value);
            });
        }
        if (body != null) {
            StringEntity s = new StringEntity(body, StandardCharsets.UTF_8);
            s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            //设置参数到请求对象中
            httpDelete.setEntity(s);
        }
        HttpResponse response = httpClient.execute(httpDelete);
        String httpEntityContent = getHttpEntityContent(response);
        httpDelete.abort();
        return httpEntityContent;
    }

    /**
     * 封装HTTP GET方法
     *
     * @param
     * @param verification TRUE为不跳过证书检测  FALSE为跳过证书检测
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */
    public static String get(String url, Map<String, Object> params, Map<String, String> headers, boolean verification) throws ClientProtocolException, IOException {
        HttpClient httpClient = verification ? HttpClients.createDefault() : wrapClient();
        HttpGet httpGet = new HttpGet();
        //设置请求和传输超时时间
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).build();
        httpGet.setConfig(requestConfig);
        if (headers != null) {
            headers.forEach((key, value) -> {
                httpGet.addHeader(key, value);
            });
        }
        if (params != null) {
            url = getUrlByParams(url, params);
        }
        httpGet.setURI(URI.create(url));
        HttpResponse response = httpClient.execute(httpGet);
        String httpEntityContent = getHttpEntityContent(response);
        httpGet.abort();
        return httpEntityContent;
    }

    private static String getUrlByParams(String url, Map<String, Object> params) {
        StringBuffer sb = new StringBuffer();
        params.forEach((key, value) -> {
            sb.append("&" + key + "=" + value);
        });
        if (sb.length() > 0) {
            String substring = sb.substring(1);
            url += url.contains("?") ? "&" : "?" + substring;
        }
        return url;
    }

    /**
     * 获得响应HTTP实体内容
     *
     * @param response
     * @return
     * @throws IOException
     * @throws UnsupportedEncodingException
     */
    private static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String line = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (line != null) {
                sb.append(line + "\n");
                line = br.readLine();
            }
            return sb.toString();
        }
        return null;
    }

    public static HttpClient wrapClient() {
        HttpClients.createDefault();
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager trustManager = new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                }

                public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                }
            };
            ctx.init(null, new TrustManager[]{trustManager}, null);
            SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
            return HttpClients.custom()
                    .setSSLSocketFactory(ssf)
                    .build();
        } catch (Exception e) {
            return HttpClients.createDefault();
        }
    }
}

2、调用解析

try {
    HashMap<String, String> map = new HashMap<>();
    map.put("app_id",appid);
    map.put("app_secret",appSecret);
    map.put("grant_type","client_credentials");

    String res = HttpClientUtils.post(host + "/oauth/token", JSON.toJSONString(map), null, false);
    JSONObject jsonObject = JSONObject.parseObject(res);
    if(jsonObject.containsKey("code") && jsonObject.getString("code").equals("0")){
        return JSONObject.parseObject(jsonObject.getString("result"),PushToken.class);
    }else{
        throw new ServiceException(res);
    }
}catch (ServiceException e){
    throw new ServiceException(e);
}catch (Exception e){
    e.printStackTrace();
}

三、路由代理

1、工具类

@Slf4j
@Component
public class RoutingDelegateUtil {

    @Resource
    //@Qualifier(value = "remoteRestTemplate")
    private RestTemplate restTemplate;

    /**
     * 上传form表单,文件
     */
    private final static String CONTENT_TYPE_FORM = "multipart/form-data;";

    /**
     * 请求转发统一处理
     *
     * @param request  原请求对象
     * @param routeUrl 路由地址,统一前缀,重定向目标主机域名(带协议及端口)
     * @param prefix   需要去除的前缀
     * @return
     * @throws Exception
     */
    public ResponseEntity<String> redirect(HttpServletRequest request, String routeUrl, String prefix) throws Exception {
        String contentType = request.getContentType();
        log.info("getContentType={}", contentType);
        // multipart/form-data处理
        if (StringUtils.isNotEmpty(contentType) && contentType.contains(CONTENT_TYPE_FORM)) {
            return redirectFile(request, routeUrl);
        } else {
            return redirect(request, routeUrl, prefix, String.class);
        }
    }

    /**
     * 上传form表单,文件
     * <p>
     * 请求转发处理
     *
     * @param request  原请求对象
     * @param routeUrl 重定向目标主机域名(带协议及端口)
     * @return
     * @throws IOException
     */
    public ResponseEntity<String> redirectFile(HttpServletRequest request, String routeUrl) throws IOException {
        // build up the redirect URL
        String redirectUrl = createRedictUrl(request, routeUrl, "");
        log.info("redirectFile redirectUrl={}", redirectUrl);
        String method = request.getMethod();
        //设置请求头
        MultiValueMap<String, String> headers = parseRequestHeader(request);

        // 组装form参数
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        StandardMultipartHttpServletRequest standardMultipartHttpServletRequest = (StandardMultipartHttpServletRequest) request;
        // 组装form参数-文件
        MultiValueMap<String, MultipartFile> multiValueMap = standardMultipartHttpServletRequest.getMultiFileMap();
        for (Map.Entry<String, List<MultipartFile>> entries : multiValueMap.entrySet()) {
            for (MultipartFile multipartFile : entries.getValue()) {
                String fileName = multipartFile.getOriginalFilename();
                log.info("redirectFile MultipartFile: fileName={}", fileName);
                File file = File.createTempFile("spw-", fileName);
                multipartFile.transferTo(file);
                FileSystemResource fileSystemResource = new FileSystemResource(file);
                form.add(entries.getKey(), fileSystemResource);
            }
        }
        // 组装form参数-一般属性
        Enumeration<String> enumeration = standardMultipartHttpServletRequest.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name = enumeration.nextElement();
            String value = standardMultipartHttpServletRequest.getParameter(name);
            log.info("redirectFile enumeration: name={}, value={}", name, value);
            form.add(name, value);
        }

        // 用HttpEntity封装整个请求报文
        HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(form, headers);

        return restTemplate.exchange(redirectUrl, HttpMethod.valueOf(method), formEntity, String.class);
    }

    /**
     * 非form-data请求转发处理
     *
     * @param request  原请求对象
     * @param routeUrl 重定向目标主机域名(带协议及端口)
     * @param prefix    需要去除的前缀
     * @param clazz 结果类型
     * @return
     * @throws Exception
     */
    public <T> ResponseEntity<T> redirect(HttpServletRequest request, String routeUrl, String prefix, Class<T> clazz) throws Exception {
        // build up the redirect URL
        String redirectUrl = createRedictUrl(request, routeUrl, prefix);
        log.info("redirectUrl={}", redirectUrl);
        RequestEntity requestEntity = createRequestEntity(request, redirectUrl);
        return restTemplate.exchange(requestEntity, clazz);
    }

    /**
     * 构建重定向地址
     *
     * @param request  原请求对象
     * @param routeUrl 重定向目标主机域名(带协议及端口)
     * @param prefix   需要去除的前缀
     * @return
     */
    private String createRedictUrl(HttpServletRequest request, String routeUrl, String prefix) {
        String queryString = request.getQueryString();
        return routeUrl + request.getRequestURI().substring(1).replace(prefix, "") +
                (queryString != null ? "?" + queryString : "");
    }

    /**
     * 构建请求实体
     *
     * @param request 原请求对象
     * @param url     新目标路由URL
     * @return
     * @throws URISyntaxException
     * @throws IOException
     */
    private RequestEntity createRequestEntity(HttpServletRequest request, String url) throws URISyntaxException, IOException {
        String method = request.getMethod();
        HttpMethod httpMethod = HttpMethod.resolve(method);
        MultiValueMap<String, String> headers = parseRequestHeader(request);
        byte[] body = parseRequestBody(request);
        return new RequestEntity<>(body, headers, httpMethod, new URI(url));
    }

    /**
     * 解析请求体
     *
     * @param request
     * @return
     * @throws IOException
     */
    private byte[] parseRequestBody(HttpServletRequest request) throws IOException {
        InputStream inputStream = request.getInputStream();
        return StreamUtils.copyToByteArray(inputStream);
    }

    /**
     * 解析请求头
     *
     * @param request
     * @return
     */
    private MultiValueMap<String, String> parseRequestHeader(HttpServletRequest request) {
        HttpHeaders headers = new HttpHeaders();
        List<String> headerNames = Collections.list(request.getHeaderNames());
        for (String headerName : headerNames) {
            List<String> headerValues = Collections.list(request.getHeaders(headerName));
            for (String headerValue : headerValues) {
                headers.add(headerName, headerValue);
            }
        }
        return headers;
    }
}

2、工具类调用

@RequestMapping("/sys-monitor/**")
    @Description("服务监控分发")
    public ResultJson transmit(HttpServletRequest request, @RequestParam(value = "ip", required = false, defaultValue = "127.0.0.1") String ip) throws Exception {
        String routeUrl = "http://" + ip + ":端口";
        ResponseEntity<ResultJson> responseEntity = restRoute.redirect(request, routeUrl, "sys-monitor", ResultJson.class);
        return responseEntity.getBody();
    }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/601667.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

I forgot my Plex Account PIN; how can I reset it? How can I change my PIN?

If you’ve set a PIN on your Plex account, it’s possible to reset or remove that PIN. Related Page: Plex Home Regular Plex Account If you know the current PIN If the current PIN is known, then simply edit the current PIN on the Settings > Users &…

Cisco NX-OS System Software - ACI 16.0(5h)

Cisco NX-OS System Software - ACI 16.0(5h) 适用于 ACI 模式下的 Cisco Nexus 9000 系列交换机 请访问原文链接&#xff1a;Cisco NX-OS System Software - ACI 16.0(5h)&#xff0c;查看最新版。原创作品&#xff0c;转载请保留出处。 作者主页&#xff1a;sysin.org Cis…

从零开始的软件测试学习之旅(七)接口测试流程及原则案例

接口测试三要素及案例 接口测试介绍接口预定义接口测试的主要作用测试接口流程如下接口测试三要素接口测试分类RESTful架构风格RESTful架构三要素要素一要素二要素三 RESTful架构风格实现restful架构案例接口测试流程接口测试原则功能测试自动化测性能测试 复习复盘 接口测试介…

AI视频教程下载:学会用AI创作文本图片音频视频

在不断发展的科技领域&#xff0c;人工智能 (AI) 是毋庸置疑的冠军&#xff0c;它是一种不断创新的力量&#xff0c;在我们的生活中扮演着越来越重要的角色。随着 2023 年的到来&#xff0c;我们诚挚地欢迎您加入人工智能精通课程的大门。 这不仅仅是一个课程&#xff0c;它专为…

外网访问内网电脑?

随着互联网的发展&#xff0c;越来越多的人需要在不同地区间进行远程访问和组网。而在复杂网络环境下&#xff0c;外网访问内网电脑常常成为一个令人头痛的问题。现在有一款名为【天联】的组网产品却解决了这个难题。 【天联】组网是由北京金万维科技有限公司自主研发的一款内网…

【管理篇】管理三步曲:任务执行(三)

目录标题 多任务并行如何应对?如何确保项目有效的执行项目执行过程中常见的问题1、目标不明确2、责任不明确3、流程不健全4、沟通不到位 如何有效执行任务 如何让流程机制有效的执行 研究任务管理&#xff0c;就是为了把事情做出来&#xff0c;产出实实在在的业绩和成果&#…

京东物流:表格技术在物流行业的敏捷应用实践

“物流大促期间&#xff0c;在出库单量积压的场景下&#xff0c;不同仓的生产操作人员需要在统一数据源的基础上进行基于自身仓情况的个性化查询分析&#xff0c;从而能够实时监控客单情况&#xff0c;防止积压。要想实现这样的功能&#xff0c;对数据分析平台的要求就非常高。…

通过 Java 操作 redis -- 基本通用命令

目录 使用 String 类型的 get 和 set 方法 使用通用命令 exists &#xff0c;del 使用通用命令 keys 使用通用命令 expire,ttl 使用通用命令 type 要想通过 Java 操作 redis&#xff0c;首先要连接上 redis 服务器&#xff0c;推荐看通过 Java 操作 redis -- 连接 redis 关…

深入探索van Emde Boas树:原理、操作与C语言实现

van Emde Boas (vEB) 树是一种高效的数据结构&#xff0c;用于处理整数集合。它是由荷兰计算机科学家Jan van Emde Boas在1977年提出的。vEB树在处理整数集合的查找、插入、删除和迭代操作时&#xff0c;能够以接近最优的时间复杂度运行。vEB树特别适合于那些元素数量在某个较小…

CSS引用

CSS定义 层叠样式表&#xff1a;&#xff08;Cascading Style Sheets,缩写为css&#xff09;,是一种样式表语言&#xff0c;用来描述HTML文档的呈现&#xff08;美化内容&#xff09; 书写位置&#xff1a;title标签下方添加style双标签&#xff0c;style标签里写入CSS代码 在s…

Spring Security 入门1

1. 概述 基本上&#xff0c;在所有的开发的系统中&#xff0c;都必须做认证(authentication)和授权(authorization)&#xff0c;以保证系统的安全性。 authentication [ɔ,θɛntɪ’keʃən] 认证 authorization [,ɔθərɪ’zeʃən] 授权 以论坛举例子&#xff1a; 【认证…

Covalent引入五个新网络运营商,提升去中心化特性和数据安全性

为了进一步扩大运营商基础以并践行去中心化网络基础设施的宗旨&#xff0c;Covalent Network&#xff08;CQT&#xff09;在网络中引入了五个新的区块样本生产者&#xff08;BSPs&#xff09;角色。该举措不仅重申了 Covalent Network&#xff08;CQT&#xff09;对社区驱动协议…

Dynamics 365入门:轻松创建您的首个应用

大家好&#xff0c;我是嘻嘻一个从事软件开发的老兵&#xff0c;需要交流可以加VX:lilinsans_weixin, 今天接上篇&#xff1a; 注册 Dynamics 365后&#xff0c;如果创建自己的第一个应用 注册完试用版可以以试用30天。今天我就分享一下如何创建第一个应用 1、Dynamics 36…

##08 数据加载与预处理:PyTorch的心脏

文章目录 前言深入理解torch.utils.data数据集(Dataset)数据加载器(DataLoader) 实战演练&#xff1a;创建自定义数据集数据转换(Transform)数据加载总结 前言 在深度学习的宇宙中&#xff0c;数据是燃料&#xff0c;模型是发动机。而在PyTorch的世界中&#xff0c;torch.util…

制作微信小程序的常见问题,2024新手小白入门必看

在当今高度数字化的世界&#xff0c;移动应用已经在日常生活和工作中不可或缺。在众多的应用程序中&#xff0c;有一个平台在中国市场上脱颖而出&#xff0c;占有绝对的一席之地——微信。 虽然被称为世界上最流行的消息和社交媒体平台之一&#xff0c;但微信提供了一个让其能…

计算机网络5——运输层1概述与UDP

文章目录 一、协议概述1、进程之间通信2、运输层的两个主要协议3、运输层的端口1&#xff09;服务器端使用的端口号2&#xff09;客户端使用的端口号 二、用户数据报协议 UDP1、UDP 概述2、案例分析3、UDP的首部格式 一、协议概述 1、进程之间通信 从通信和信息处理的角度看&…

邮件群发还能用吗

邮件群发仍然可以使用。不过&#xff0c;在进行邮件群发时&#xff0c;可能会遇到一些问题&#xff0c;如选择合适的邮件群发软件、应对垃圾邮件过滤器的挑战、管理收件人列表、邮件内容的个性化和定制、邮件投递的时间管理以及避免被列入黑名单等。 为了优化邮件群发的效果&a…

微信小程序知识点归纳(一)

前言&#xff1a;适用于有一定基础的前端开发同学&#xff0c;完成从网页开发到小程序开发的知识转换。 先立框架&#xff0c;后砌墙壁 回顾&#xff1a;了解微信小程序开发流程-CSDN博客 初始页面结构&#xff0c;三部分pages、utils、配置&#xff0c;分别存放页面、工具类…

图形渲染在AI去衣技术中的奇妙之旅

在这个数字化飞速发展的时代&#xff0c;人工智能&#xff08;AI&#xff09;已经成为了我们生活中不可或缺的一部分。它像一位神秘的魔法师&#xff0c;以其不可思议的力量改变着我们的世界。今天&#xff0c;我要和大家探讨的&#xff0c;是一个颇具争议却技术含金量极高的话…

PostgreSQL自带的命令行工具13- pg_waldump

PostgreSQL自带的命令行工具13- pg_waldump 基础信息 OS版本&#xff1a;Red Hat Enterprise Linux Server release 7.9 (Maipo) DB版本&#xff1a;16.2 pg软件目录&#xff1a;/home/pg16/soft pg数据目录&#xff1a;/home/pg16/data 端口&#xff1a;5777pg_waldump 是 Po…
最新文章