使用Java和不同HTTP客户端库发送各种Content-Type类型请求

news2024/12/28 21:45:48

1. 引言

在HTTP协议中,Content-Type头用于指示请求或响应中数据的媒体类型。了解和正确设置Content-Type 对于确保客户端和服务器之间正确解析数据至关重要。本文将介绍如何使用Java 和 不同的HTTP客户端发送各种Content-Type 类型的请求。

2. 常见的Content-Type 类型

以下是几种常见的Content-Type 类型及其应用场景:

  • application/json

    • 描述: 用于发送JSON格式的数据。
    • 传参方式: 通常在请求体中传递JSON字符串。
    • 示例:
      POST /api/data HTTP/1.1
      Host: example.com
      Content-Type: application/json
      {
      	"name": "John",
      	"age": 30
      }
      
  • application/x-www-form-urlencoded

    • 描述: 用于发送键值对数据,通常用于表单提交。

    • 传参方式: 数据以键值对的形式编码在请求体中,格式类似于查询字符串。

    • 示例:

      POST /api/data HTTP/1.1
      Host: example.com
      Content-Type: application/x-www-form-urlencoded
      
      name=John&age=30
      

      请求头:

      在这里插入图片描述

      解析前:

      在这里插入图片描述
      在这里插入图片描述

      解析后:

      在这里插入图片描述

  • multipart/form-data

    • 描述: 用于发送包含文件上传的表单数据。

    • 传参方式: 数据以多部分形式编码,每部分包含一个表单字段或文件。

    • 示例:

      POST /api/data HTTP/1.12
      Host: example.com3
      Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW //指定分界线标识符
      
      ------WebKitFormBoundary7MA4YWxkTrZu0gW
      Content-Disposition: form-data; name="name"
      
      John
      -----WebKitFormBoundary7MA4YWxkTrZu0gW
      Content-Disposition: form-data; name="file"; filename="example.txt"11
      Content-Type: text/plain
      
      (file content)
       -----WebKitFormBoundary7MA4YWxkTrZu0gW--
      

      请求头

      在这里插入图片描述

      解析前:

      在这里插入图片描述

      解析后:

      在这里插入图片描述

  • text/plain

    • 描述: 用于发送纯文本数据。
    • 传参方式: 数据以纯文本形式编码在请求体中。
    • 示例:
      POST /api/data HTTP/1.1
      Host: example.com
      Content-Type: text/plain
      
      This is plain text.
      
  • application/xml

    • 描述: 用于发送XML格式的数据。
    • 传参方式: 数据以XML格式编码在请求体中。
    • 示例:
      POST /api/data HTTP/1.1
      Host: example.com
      Content-Type: application/xml
      
      <person>
      	<name>John</name>
      	<age>30</age>
      </person>
      
  • application/oct-stream

    • 描述: 用于发送二进制数据,通常用于文件下载或上传。
    • 传参方式: 数据以二进制形式编码在请求体中。
    • 示例:
      POST /api/data HTTP/1.1
      Host: example.com
      Content-Type: application/octet-stream
      
      (binary data)
      

3. 使用Hutool发送HTTP请求

Hutool 是一个Java工具包,简化了日常开发中的许多任务。以下是使用Hutool发送各种Content-Type 类型的请求的示例代码。

1.安装Hutool

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.10</version>
</dependency>

2. 示例代码

1. application/json

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;

public class JsonExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String json = JSONUtil.toJsonStr(Map.of("name", "John", "age", 30));

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .body(json)
                .execute();

        System.out.println(response.body());
    }
}

2. application/x-www-form-urlencoded

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

public class FormUrlEncodedExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
      
       	Map<String,String> map = new HashMap();
        map.put("name", "John")
        map.put("age", "30") 

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "application/x-www-form-urlencoded")
                .form(map)
                .execute();

        System.out.println(response.body());
    }
}

3. multipart/form-data

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

public class MultipartExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
      
       	Map<String,Object> map = new HashMap();
        map.put("name", "John")
        map.put("age", new File("path/to/your/file.txt")) 

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "multipart/form-data")
                .form(map)
                .execute();

        System.out.println(response.body());
    }
}

4. text/plain

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

public class PlainTextExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String text = "This is plain text.";

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "text/plain")
                .body(text)
                .execute();

        System.out.println(response.body());
    }
}

5. application/xml

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

public class XmlExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String xml = "<person><name>John</name><age>30</age></person>";

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "application/xml")
                .body(xml)
                .execute();

        System.out.println(response.body());
    }
}

6. application/octet-stream

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;

public class OctetStreamExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        byte[] data = "binary data".getBytes();

        HttpResponse response = HttpRequest.post(url)
                .header("Content-Type", "application/octet-stream")
                .body(data)
                .execute();

        System.out.println(response.body());
    }
}

4. OkHttp

OkHttp是一个高效的HTTP客户端。以下是使用OkHttp发送各种Content-Type类型的请求的示例代码。

1. 安装OkHttp

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.9.3</version>
</dependency>

2. 示例代码

1. application/json

import okhttp3.*;

import java.io.IOException;

public class JsonExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String json = "{\"name\":\"John\", \"age\":30}";

        OkHttpClient client = new OkHttpClient();
        RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

2. application/x-www-form-urlencoded

import okhttp3.*;

import java.io.IOException;

public class FormUrlEncodedExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";

        OkHttpClient client = new OkHttpClient().newBuilder()
                .connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
                .build();
      
      
        Map<String,String> map = new HashMap();
        map.put("name", "John")
        map.put("age", "30")  
      
        // 构建请求体
        MultipartBody.Builder builder = new MultipartBody.Builder()
                .setType(MultipartBody.FORM);

        // 动态添加文本参数
        for (Map.Entry<String, String> entry : map.entrySet()) {
            builder.addFormDataPart(entry.getKey(), entry.getValue());
        }

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

3. multipart/form-data

import okhttp3.*;

import java.io.File;
import java.io.IOException;

public class MultipartExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        File file = new File("path/to/your/file.txt");

        OkHttpClient client = new OkHttpClient();
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("name", "John")
                .addFormDataPart("file", file.getName(),
                        RequestBody.create(file, MediaType.parse("application/octet-stream")))
                .build();

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

4. text/plain

import okhttp3.*;

import java.io.IOException;

public class PlainTextExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String text = "This is plain text.";

        OkHttpClient client = new OkHttpClient();
        RequestBody body = RequestBody.create(text, MediaType.parse("text/plain"));

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

5. application/xml

import okhttp3.*;

import java.io.IOException;

public class XmlExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String xml = "<person><name>John</name><age>30</age></person>";

        OkHttpClient client = new OkHttpClient();
        RequestBody body = RequestBody.create(xml, MediaType.parse("application/xml"));

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

6. application/octet-stream

import okhttp3.*;

import java.io.IOException;

public class OctetStreamExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        byte[] data = "binary data".getBytes();

        OkHttpClient client = new OkHttpClient();
        RequestBody body = RequestBody.create(data, MediaType.parse("application/octet-stream"));

        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            System.out.println(response.body().string());
        }
    }
}

5. Apache HttpClient

Apache HttpClient是一个强大的HTTP客户端,支持多种HTTP协议特性。以下是使用Apache HttpClient发送各种Content-Type类型的请求的示例代码。

1. 安装Apache HttpClient

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.13</version>
</dependency>

2. 示例代码

1. application/json

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class JsonExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String json = "{\"name\":\"John\", \"age\":30}";

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        StringEntity entity = new StringEntity(json);
        entity.setContentType("application/json");
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

2. application/x-www-form-urlencoded

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FormUrlEncodedExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        List<BasicNameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("name", "John"));
        params.add(new BasicNameValuePair("age", "30"));
        HttpEntity entity = new UrlEncodedFormEntity(params);
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

3. multipart/form-data

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.io.IOException;

public class MultipartExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        File file = new File("path/to/your/file.txt");

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        HttpEntity entity = MultipartEntityBuilder.create()
                .addTextBody("name", "John", ContentType.TEXT_PLAIN)
                .addBinaryBody("file", file, ContentType.APPLICATION_OCTET_STREAM, file.getName())
                .build();
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

4. text/plain

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class PlainTextExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String text = "This is plain text.";

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        StringEntity entity = new StringEntity(text);
        entity.setContentType("text/plain");
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

5. application/xml

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class XmlExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        String xml = "<person><name>John</name><age>30</age></person>";

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        StringEntity entity = new StringEntity(xml);
        entity.setContentType("application/xml");
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

6. application/octet-stream

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class OctetStreamExample {
    public static void main(String[] args) throws IOException {
        String url = "http://example.com/api/data";
        byte[] data = "binary data".getBytes();

        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        HttpEntity entity = new ByteArrayEntity(data);
        entity.setContentType("application/octet-stream");
        post.setEntity(entity);

        try (CloseableHttpResponse response = client.execute(post)) {
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                System.out.println(EntityUtils.toString(responseEntity));
            }
        }
    }
}

6. RestTemplate

RestTemplate是Spring框架中的一个同步客户端,用于简化与HTTP服务器的通信。以下是使用RestTemplate发送各种Content-Type类型的请求的示例代码。

1. 安装Spring Boot Starter Web

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2. 示例代码

1. application/json

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

public class JsonExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        Map<String, Object> json = new HashMap<>();
        json.put("name", "John");
        json.put("age", 30);

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<Map<String, Object>> entity = new HttpEntity<>(json, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

2. application/x-www-form-urlencoded

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class FormUrlEncodedExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("name", "John");
        params.add("age", "30");
        HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(params, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

3. multipart/form-data

import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class MultipartExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String filePath = "path/to/your/file.txt";

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("name", "John");
        params.add("file", new FileSystemResource(filePath));
        HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(params, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

4. text/plain

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

public class PlainTextExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String text = "This is plain text.";

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.TEXT_PLAIN);
        HttpEntity<String> entity = new HttpEntity<>(text, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

5. application/xml

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

public class XmlExample {
    public static void main(String[] args) {
        String url = "http://example.com/api/data";
        String xml = "<person><name>John</name><age>30</age></person>";

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);
        HttpEntity<String> entity = new HttpEntity<>(xml, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

6. application/octet-stream

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class OctetStreamExample {
    public static void main(String[] args) throws Exception {
        String url = "http://example.com/api/data";
        Path path = Paths.get("path/to/your/file.txt");
        byte[] data = Files.readAllBytes(path);

        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        HttpEntity<byte[]> entity = new HttpEntity<>(data, headers);

        String response = restTemplate.postForObject(url, entity, String.class);
        System.out.println(response);
    }
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

YOLO11改进-注意力-引入自调制特征聚合模块SMFA

本篇文章将介绍一个新的改进机制——SMFA&#xff08;自调制特征聚合模块&#xff09;&#xff0c;并阐述如何将其应用于YOLOv11中&#xff0c;显著提升模型性能。随着深度学习在计算机视觉中的不断进展&#xff0c;目标检测任务也在快速发展。YOLO系列模型&#xff08;You Onl…

【单片机通讯协议】—— 常用的UART/I2C/SPI等通讯协议的基本原理与时序分析

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、通信基本知识1.1 MCU的参见外设1.2 通信的分类按基本的类型从传输方向上来分 二、UART&#xff08;串口通讯&#xff09;2.1 简介2.2 时序图分析2.3 UART的…

Docker 部署 plumelog 最新版本 实现日志采集

1.配置plumelog.yml version: 3 services:plumelog:#此镜像是基于plumelog-3.5.3版本image: registry.cn-hangzhou.aliyuncs.com/k8s-xiyan/plumelog:3.5.3container_name: plumelogports:- "8891:8891"environment:plumelog.model: redisplumelog.queue.redis.redi…

Empire Lupin One靶机

靶机 ip&#xff1a;192.168.152.157 我们访问页面 第一步信息收集 我们先扫描一下端口 扫描到开启了 22 端口 80 端口 我们使用御剑扫描一下网站的后台 我们挨个访问一下 发现 apache 的帮助页面&#xff0c;暂时记录&#xff0c;看看等会有没有需要 我们查看到 robots.tx…

WPF 绘制过顶点的圆滑曲线(样条,贝塞尔)

项目中要用到样条曲线&#xff0c;必须过顶点&#xff0c;圆滑后还不能太走样&#xff0c;捣鼓一番&#xff0c;发现里面颇有玄机&#xff0c;于是把我多方抄来改造的方法发出来&#xff0c;方便新手&#xff1a; 如上图&#xff0c;看代码吧&#xff1a; -------------------…

绝美的数据处理图-三坐标轴-散点图-堆叠图-数据可视化图

clc clear close all %% 读取数据 load(MyColor.mat) %读取颜色包for iloop 1:25 %提取工作表数据data0(iloop) {readtable(data.xlsx,sheet,iloop)}; end%% 解析数据 countzeros(23,14); for iloop 1:25index(iloop) { cell2mat(table2array(data0{1,iloop}(1,1)))};data(i…

hdfs命令(三)- hdfs 管理命令(三)- hdfs dfsadmin命令

文章目录 前言一、hdfs分布式文件系统管理命令1. 介绍2. 语法及解释3. 命令3.1 生成HDFS集群的状态报告3.1.1 语法及解释3.1.2 示例 3.2 重新加载配置文件并更新NameNode中的节点列表3.3 刷新指定DataNode上的NameNode信息3.3.1 语法 3.4 获取并显示指定DataNode的信息3.4.1 语…

Word论文交叉引用一键上标

Word论文交叉引用一键上标 1.进入Microsoft word使用CtrlH快捷键或单击替换按钮 2.在查找内容中输入[^#] 3.鼠标点击&#xff0c;标签为“替换为&#xff1a;”的文本框&#xff0c;注意光标一定要打在图红色方框圈中的文本框中&#xff01; 4.点击格式选择字体 5.勾选上标…

JAVA:最简单多线程方法调用

以下介绍在JAVA中&#xff0c;最简单调用多线程的方法。 在需要使用多线程方法的类中&#xff0c;新增线程类Thread并实现方法run。 //定义多线程class ThreadLinePoints extends Thread{private String m;public ThreadLinePoints(){}public ThreadLinePoints(String m){this…

Hadoop中MapReduce过程中Shuffle过程实现自定义排序

文章目录 Hadoop中MapReduce过程中Shuffle过程实现自定义排序一、引言二、实现WritableComparable接口1、自定义Key类 三、使用Job.setSortComparatorClass方法2、设置自定义排序器3、自定义排序器类 四、使用示例五、总结 Hadoop中MapReduce过程中Shuffle过程实现自定义排序 一…

科技云报到:人工智能时代“三大件”:生成式AI、数据、云服务

科技云报到原创。 就像自行车、手表和缝纫机是工业时代的“三大件”。生成式AI、数据、云服务正在成为智能时代的“新三大件”。加之全球人工智能新基建加速建设&#xff0c;成为了人类社会数字化迁徙的助推剂&#xff0c;让新三大件之间的耦合越来越紧密。从物理世界到数字世…

Windows 11 中部署 Linux 项目

一、总体思路 在 Windows 11 中部署 Linux 项目&#xff0c;主要是借助 Windows Subsystem for Linux&#xff08;WSL&#xff09;来实现。在WSL中新建基于Linux的项目虚拟环境&#xff0c;以供WIN下已克隆的项目使用。WSL 允许在 Windows 系统上运行原生的 Linux 二进制可执行…

【ETCD】【实操篇(十五)】etcd集群成员管理:如何高效地添加、删除与更新节点

etcd 是一个高可用的分布式键值存储&#xff0c;广泛应用于存储服务发现、配置管理等场景。为了确保集群的稳定性和可扩展性&#xff0c;管理成员节点的添加、删除和更新变得尤为重要。本文将指导您如何在etcd集群中处理成员管理&#xff0c;帮助您高效地维护集群节点。 目录 …

数据结构与算法Python版 平衡二叉查找树AVL

文章目录 一、平衡二叉查找树二、AVL树测试三、AVL树-算法分析 一、平衡二叉查找树 平衡二叉查找树-AVL树的定义 AVL树&#xff1a;在key插入时一直保持平衡的二叉查找树。可以利用AVL树实现抽象数据类型映射Map。与二叉查找树相比&#xff0c;AVL树基本上与二叉查找树的实现…

【Redis】Redis 安装与启动

在实际工作中&#xff0c;大多数企业选择基于 Linux 服务器来部署项目。本文演示如何使用 MobaXterm 远程连接工具&#xff0c;在 CentOS 7 上安装和启动 Redis 服务&#xff08;三种启动方式&#xff0c;包括默认启动、指定配置启动和开机自启&#xff09;。在安装之前&#x…

通过Js动态控制Bootstrap模态框-弹窗效果

目的&#xff1a;实现弹出窗、仅关闭弹窗之后才能操作&#xff08;按ESC可退出&#xff09;。自适应宽度与高度、当文本内容太多时、添加滚动条效果。 效果图 源码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8">…

el-table合并单元行后的多选框选中问题

问题描述 合并单元行以后&#xff0c;首列的多选框也会合并&#xff0c;此时选中该多选框其实是只选中了合并单元行的第一行的多选框&#xff0c;其他的都未被选中。 解决方案 原本想着手动去修改表头的半选状态和全选状态 &#xff0c;但是没有找到相关方法&#xff0c;后面觉…

电脑缺失libcurl.dll怎么解决?详解电脑libcurl.dll文件丢失问题

一、libcurl.dll文件丢失的原因 libcurl.dll是一个用于处理URL传输的库文件&#xff0c;广泛应用于各种基于网络的应用程序。当这个文件丢失时&#xff0c;可能会导致相关应用程序无法正常运行。以下是libcurl.dll文件丢失的一些常见原因&#xff1a; 软件安装或卸载不完整&a…

图文教程:使用PowerDesigner导出数据库表结构为Word/Html文档

1、第一种情况-无数据库表&#xff0c;但有数据模型 1.1 使用PowerDesigner已完成数据建模 您已经使用PowerDesigner完成数据库建模&#xff0c;如下图&#xff1a; 1.2 Report配置和导出 1、点击&#xff1a;Report->Reports&#xff0c;如下图&#xff1a; 2、点击&…

UE--如何用 Python 调用 C++ 及蓝图函数

前言 先讲下如何用 Python 调用 C 函数吧。 详细可见我的上篇文章 最关键的一点就是得在函数上加一个宏&#xff1a;UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable) static bool GetOrCreatePackage(const FString& PackagePath, UPackage*& OutPackag…