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

单元测试实战(五)普通类的测试

为鼓励单元测试,特分门别类示例各种组件的测试代码并进行解说,供开发人员参考。

本文中的测试均基于JUnit5。

单元测试实战(一)Controller 的测试

单元测试实战(二)Service 的测试    

单元测试实战(三)JPA 的测试    

单元测试实战(四)MyBatis-Plus 的测试

​​​​​​​单元测试实战(五)普通类的测试

单元测试实战(六)其它

概述

普通类或曰POJO的测试,是最简单的一种情况,大多数情况下只使用JUnit即可。万一有不易实例化的外部依赖,也可以用Mockito的@Mock来模拟。这类测试一般应脱离Spring上下文来进行。

需要的话,在每个测试之前应清理/重置测试数据,一般为方法参数或待测类实例;断言应主要检查待测类的行为是否符合预期。

依赖

大多数普通类测试只依赖JUnit,但作为一般实践,我们通常也带上Spring Boot自己的测试工具集。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope>
</dependency>
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><scope>test</scope>
</dependency>

示例

以下是一个BigDecimal的包装类,实现了一些BigDecimal的最佳实践;该类是我们的待测试类:

package com.aaa.sdk.utils;import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Objects;/*** BigDecimal的包装类,封装了以下实践:* <li>不允许null值(使用工厂方法创建实例时会直接报错)。</li>* <li>避免double构造传参造成精度丢失。</li>* <li>封装equals,强制使用compareTo来比较。</li>* <li>封装格式化输出(补零对齐,默认两位)。</li>* <li>封装加减乘除,尤其除法,强制使用BigDecimal的三参方法避免无限小数报错。</li>* <li>直观的判断正数、负数、零的方法。</li>* <br/>** 本类设计为不可变对象,非读方法(加减乘除、取反、四舍五入等)都会产生新对象。** @author ioriogami**/
public class DecimalWrapper implements Comparable<DecimalWrapper> {/*** 默认精度,保留两位。*/public static final int DEFAULT_SCALE = 2;private final BigDecimal decimal;private DecimalWrapper(BigDecimal decimal) {Objects.requireNonNull(decimal);this.decimal = decimal;}// 以下工厂方法/*** 通过一个BigDecimal对象构造DecimalWrapper实例。* @param decimal 本wrapper代表的BigDecimal对象*/public static DecimalWrapper of(BigDecimal decimal) {return new DecimalWrapper(decimal);}/*** 通过一个String实例构造DecimalWrapper实例。* @param s 字符串数值*/public static DecimalWrapper of(String s) {return of(new BigDecimal(s));}/*** 通过一个double实例构造DecimalWrapper实例。* @param d double数值*/public static DecimalWrapper of(double d) {return of(new BigDecimal(String.valueOf(d)));}/*** 通过一个float实例构造。* @param f float数值*/public static DecimalWrapper of(float f) {return of(new BigDecimal(String.valueOf(f)));}// 以下一般接口/*** 获取底层的BigDecimal对象*/public BigDecimal toBigDecimal() {return decimal;}/*** 获取double值。*/public Double toDouble() {return decimal.doubleValue();}@Overridepublic String toString() {return decimal.toPlainString();}@Overridepublic int hashCode() {return decimal.hashCode();}@Overridepublic boolean equals(Object obj) {if (obj instanceof DecimalWrapper) {DecimalWrapper other = (DecimalWrapper) obj;return decimal.compareTo(other.decimal) == 0;}return false;}@Overridepublic int compareTo(DecimalWrapper that) {if (that == null) return 1;return this.decimal.compareTo(that.decimal);}// 以下格式化输出/*** 四舍五入保留两位。* @return 一个新的DecimalWrapper对象*/public DecimalWrapper round() {return round(DEFAULT_SCALE, RoundingMode.HALF_UP);}/*** 四舍五入保留i位。* @param scale 精度,即i,保留几位。* @return 一个新的DecimalWrapper对象*/public DecimalWrapper round(int scale) {return round(scale, RoundingMode.HALF_UP);}/*** m舍n入保留i位。** @param scale 精度,即i,保留几位。* @param mode 舍入策略(m和n)。* @return 一个新的DecimalWrapper对象*/public DecimalWrapper round(int scale, RoundingMode mode) {return of(decimal.setScale(scale, mode));}/*** 获得四舍五入保留两位(强制补0)后的字符串。*/public String format() {return new DecimalFormat("0.00").format(decimal.setScale(DEFAULT_SCALE, RoundingMode.HALF_UP));}/*** 获得四舍五入保留i位(强制补0)后的字符串。* @param scale 精度,即i,保留几位。*/public String format(int scale) {return format(scale, RoundingMode.HALF_UP);}/*** 获得m舍n入保留scale位(强制补0)后的字符串。不会影响本身的值。* @param scale 精度,即i,保留几位。* @param mode 舍入策略(m和n),若为null则默认四舍五入。* @return 格式化后的字符串。*/public String format(int scale, RoundingMode mode) {if (scale <= 0) throw new IllegalArgumentException("精度必须大于0");if (mode == null) mode = RoundingMode.HALF_UP;StringBuilder buff = new StringBuilder("0.");for (int i = 0; i < scale; i++) {buff.append("0");}return new DecimalFormat(buff.toString()).format(decimal.setScale(scale, mode));}// 以下加减乘除、取反/*** 加法。*/public DecimalWrapper add(DecimalWrapper other) {if (other == null) throw new IllegalArgumentException("操作数为null,无法进行加法运算。");return of(decimal.add(other.decimal));}/*** 减法。*/public DecimalWrapper subtract(DecimalWrapper other) {if (other == null) throw new IllegalArgumentException("操作数为null,无法进行减法运算。");return of(decimal.subtract(other.decimal));}/*** 乘法。*/public DecimalWrapper multiply(DecimalWrapper other) {if (other == null) throw new IllegalArgumentException("操作数为null,无法进行乘法运算。");return of(decimal.multiply(other.decimal));}/*** 除法。*/public DecimalWrapper divide(DecimalWrapper other) { // 使用三参除法,避免结果为无限小数时报错。return divide(other, DEFAULT_SCALE, RoundingMode.HALF_UP);}/*** 除法,指定精度和舍入策略。*/public DecimalWrapper divide(DecimalWrapper other, int scale, RoundingMode mode) {if (other == null) throw new IllegalArgumentException("操作数为null,无法进行除法运算。");if (scale <= 0) throw new IllegalArgumentException("精度必须大于0");if (mode == null) mode = RoundingMode.HALF_UP;return of(decimal.divide(other.decimal, scale, mode));}/*** 取反。*/public DecimalWrapper negate() {return of(decimal.negate());}/*** 判断是否零值,不管到底是0.0、0.00还是0.0000..*/public boolean isZero() {return decimal.signum() == 0;}/*** 判断是否正数。*/public boolean isPositive() {return decimal.signum() == 1;}/*** 判断是否正数。*/public boolean isNegative() {return decimal.signum() == -1;}
}

以下是对DecimalWrapper进行测试的测试类:

package com.aaa.sdk.utils;import java.math.BigDecimal;
import java.math.RoundingMode;import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.*;class DecimalWrapperTest {@Testvoid testConstructBigDecimal() {DecimalWrapper d = DecimalWrapper.of(new BigDecimal("1.11"));assertEquals("1.11", d.format());}@Testvoid testConstructDouble() {DecimalWrapper d = DecimalWrapper.of(1.11);assertEquals("1.11", d.format());}@Testvoid testConstructString() {DecimalWrapper d = DecimalWrapper.of("1.11");assertEquals("1.11", d.format());}@Testvoid testConstructFloat() {DecimalWrapper d = DecimalWrapper.of(1.1f);assertEquals("1.10", d.format());}@Testvoid testConstructNullParam() {try {DecimalWrapper.of((String) null);fail("should not get here!");} catch (NullPointerException npe) {}try {DecimalWrapper.of((Double) null);fail("Should not get here!");} catch (NullPointerException npe) {}try {DecimalWrapper.of((Float) null);fail("Should not get here!");} catch (NullPointerException npe) {}try {DecimalWrapper.of((BigDecimal) null);fail("Should not get here!");} catch (NullPointerException npe) {}}@Testvoid testComparison() {DecimalWrapper d1 = DecimalWrapper.of(1.1);DecimalWrapper d2 = DecimalWrapper.of(1.2);DecimalWrapper d3 = DecimalWrapper.of(1.0);assertTrue(d1.compareTo(d2) < 0);assertTrue(d2.compareTo(d1) > 0);assertTrue(d3.compareTo(d1) < 0);assertTrue(d3.compareTo(d2) < 0);DecimalWrapper d4 = DecimalWrapper.of("1.00");assertTrue(d3.compareTo(d4) == 0);DecimalWrapper d5 = null;assertTrue(d3.compareTo(d5) > 0);}@Testvoid testToDecimal() {DecimalWrapper d1 = DecimalWrapper.of(1.11);assertEquals(d1.toBigDecimal(), new BigDecimal("1.11"));}@Testvoid testToDouble() {DecimalWrapper d1 = DecimalWrapper.of(1.11);assertEquals(d1.toDouble(), 1.11);}@Testvoid testEquals() {DecimalWrapper d1 = DecimalWrapper.of(1.12345);DecimalWrapper d2 = DecimalWrapper.of(1.12345f);DecimalWrapper d3 = DecimalWrapper.of("1.12345");DecimalWrapper d4 = DecimalWrapper.of(new BigDecimal("1.12345"));assertEquals(d1, d2);assertEquals(d2, d3);assertEquals(d3, d4);}@Testvoid testRoundDefault() {DecimalWrapper d1 = DecimalWrapper.of(1.12385);DecimalWrapper d2 = DecimalWrapper.of(1.12385f);DecimalWrapper d3 = DecimalWrapper.of("1.12385");DecimalWrapper d4 = DecimalWrapper.of(new BigDecimal("1.12385"));assertEquals(d1.round(), DecimalWrapper.of("1.12"));assertEquals(d2.round(), DecimalWrapper.of("1.12"));assertEquals(d3.round(), DecimalWrapper.of("1.12"));assertEquals(d4.round(), DecimalWrapper.of("1.12"));}@Testvoid testRound() {DecimalWrapper d1 = DecimalWrapper.of(1.12385);DecimalWrapper d2 = DecimalWrapper.of(1.12385f);DecimalWrapper d3 = DecimalWrapper.of("1.12385");DecimalWrapper d4 = DecimalWrapper.of(new BigDecimal("1.12385"));assertEquals(d1.round(3), DecimalWrapper.of("1.124"));assertEquals(d2.round(3), DecimalWrapper.of("1.124"));assertEquals(d3.round(3), DecimalWrapper.of("1.124"));assertEquals(d4.round(3), DecimalWrapper.of("1.124"));assertEquals(d4.round(3, RoundingMode.DOWN), DecimalWrapper.of("1.123"));}@Testvoid testFormat() {DecimalWrapper d1 = DecimalWrapper.of(1.12385);assertEquals(d1.format(), "1.12");assertEquals(d1.format(3), "1.124");assertEquals(d1.format(3, RoundingMode.DOWN), "1.123");}@Testvoid testAdd() {DecimalWrapper d1 = DecimalWrapper.of(1.12385);DecimalWrapper d2 = DecimalWrapper.of(1.12385);assertEquals(DecimalWrapper.of("2.24770"), d1.add(d2));DecimalWrapper d3 = DecimalWrapper.of(0);assertEquals(DecimalWrapper.of("1.12385"), d3.add(d2));assertTrue(d3.add(d3).isZero());}@Testvoid testSubtract() {DecimalWrapper d1 = DecimalWrapper.of(2.24770);DecimalWrapper d2 = DecimalWrapper.of(1.12385);assertEquals(DecimalWrapper.of("1.12385"), d1.subtract(d2));DecimalWrapper d3 = DecimalWrapper.of(0); // change to: 0.0assertEquals(DecimalWrapper.of("1.12385"), d2.subtract(d3));assertTrue(d2.subtract(d2).isZero());assertTrue(d3.subtract(d3).isZero());}@Testvoid testMultiply() {DecimalWrapper d1 = DecimalWrapper.of(1.12385);DecimalWrapper d2 = DecimalWrapper.of(1.12385);assertEquals(DecimalWrapper.of("1.2630388225"), d1.multiply(d2));DecimalWrapper d3 = DecimalWrapper.of(0.00);assertTrue(d2.multiply(d3).isZero());DecimalWrapper d4 = DecimalWrapper.of(-1);assertEquals(DecimalWrapper.of("-1.12385"), d1.multiply(d4));}@Testvoid testDivide() {DecimalWrapper d1 = DecimalWrapper.of(10.0);DecimalWrapper d2 = DecimalWrapper.of(3);assertEquals(DecimalWrapper.of(3.33), d1.divide(d2));DecimalWrapper d3 = DecimalWrapper.of(0);assertTrue(d3.multiply(d1).isZero());try {d1.divide(d3);fail("divide by zero, should not get here!");} catch (Exception e){}}@Testvoid testNegate() {DecimalWrapper d1 = DecimalWrapper.of(-1.12385);assertTrue(d1.isNegative());assertFalse(d1.isZero());assertFalse(d1.isPositive());DecimalWrapper d2 = d1.negate();assertTrue(d2.isPositive());assertFalse(d2.isZero());assertFalse(d2.isNegative());assertTrue(d1.add(d2).isZero());}}

测试类说明:

测试类的代码和被测类的代码都比较直观,不需做过多说明。

在该类中,我们为被测类的每个公共方法都创建了测试方法,且只用到了JUnit的@Test和Assertions;如果需要事前准备和事后清理工作,还可以加上@BeforeEach、@AfterEach、@BeforeAll、@AfterAll等方法。

第37行的testConstructNullParam是负面测试,测试当传入null值是不允许的,会抛出NullPointerException。

第101行的testRoundDefault、第113行的testRound,是对同一个方法的不同情况(精度)的测试。

私有方法的测试

私有方法不需要测试。对私有方法的测试,应通过调用它的公有方法的测试来进行。直接测试私有方法往往是一种代码“坏味道”。

虽然但是,有时候确实想给私有方法写一个测试,也不是做不到:

package com.aaa.api.auth.filter;import com.aaa.sdk.utils.Utils;
import org.junit.jupiter.api.Test;import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;import static org.junit.jupiter.api.Assertions.*;
class AuthNFilterTest {@Testvoid testExtractUsernameFromToken() throws InvocationTargetException, IllegalAccessException {String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...";AuthNFilter filter = new AuthNFilter();Method m = Utils.doGetMethod(AuthNFilter.class, "extractUsernameFromToken", String.class);//long start = System.currentTimeMillis();String user = (String) m.invoke(filter, token);//System.out.println("User is " + user + ", used " + (System.currentTimeMillis() - start) + " ms");assertEquals("ioriogami", user);}
}

第15行,我们new了一个待测试对象。

第16行,我们用反射获取了AuthNFilter类的extractUsernameFromToken私有方法(该方法接受一个String类型的参数),然后在第18行对其进行调用。

 如需对构造方法、私有方法、静态方法、final类和方法进行mock,可以使用powermock提供的增强版Mockito:PowerMockito。

总结

普通类的测试以JUnit简单测试为主,一般不需要Spring上下文。

每一个public方法都有至少一个测试;对不同的情况/分支,建议有多个测试;最好也有负面测试。当然,一个完美的测试类应该测试每个方法的正面行为、负面行为、边缘情况;并应尽可能覆盖所有分支。但在有限的时间内,我们应识别最重要的方面进行测试。

单元测试针对单个类,原则上测试类与被测类一对一。当然也可以针对一组紧密相关的类/接口编写单元测试,比如pagewindow是一个实现无界分页的小模块,由几个接口和类组成,它的单元测试就是针对这一组类的。

Mock的原理是采用字节码生成的方式对要mock的类进行sub-class,然后生成这个子类的对象,以此达到对其行为进行订制的目的。显然,这种方式会受到Java继承机制的限制:静态类/方法、final类/方法、构造器、私有方法等都不能继承,因此就难以订制。

Mockito在2.1.0中加入了对final类/方法的支持。见 https://www.cnblogs.com/yuluoxingkong/p/14813558.html。

powermock提供的增强版Mockito:PowerMockito 则对这些方面提供了全面的支持。

相关文章:

单元测试实战(五)普通类的测试

为鼓励单元测试&#xff0c;特分门别类示例各种组件的测试代码并进行解说&#xff0c;供开发人员参考。 本文中的测试均基于JUnit5。 单元测试实战&#xff08;一&#xff09;Controller 的测试 单元测试实战&#xff08;二&#xff09;Service 的测试 单元测试实战&am…...

js 迭代器iterator 和 生成器Generator 10

✌ 文章目录 一、迭代器 iterator二、使用步骤1.引入库2.读入数据 总结 一、迭代器 iterator 迭代器是帮助我们对某个数据结构进行遍历的对象 迭代器&#xff1a;是一个对象&#xff0c;帮助我们对某个数据结构进行遍历 迭代器要符合迭代器协议&#xff0c;必须要有一个特定的n…...

100套Axure RP大数据可视化大屏模板及通用组件库

106套Axure RP大数据可视化大屏模板包括了多种实用美观的可视化组件库及行业模板库&#xff0c;行业模板涵盖&#xff1a;金融、教育、医疗、政府、交通、制造等多个行业提供设计参考。 随着大数据的发展&#xff0c;可视化大屏在各行各业得到越来越广泛的应用。可视化大屏不再…...

【OpenGauss源码学习 —— 执行算子(Append算子)】

执行算子&#xff08;Append算子&#xff09; Append 算子ExecInitAppend 函数exec_append_initialize_next 函数ExecAppend 函数ExecEndAppend 函数ExecReScanAppend 函数 声明&#xff1a;本文的部分内容参考了他人的文章。在编写过程中&#xff0c;我们尊重他人的知识产权和…...

Java(一)(引用类型的参数在传递,方法重载,面向对象编程基础)

基本类型和引用类型的参数在传递的时候有什么不同? 基本类型的值传递:参数传输存储的数据值 引用类型的值传递:参数传输存储的地址值 传递数组名字的时候,传递的是数组的地址,change方法可以通过地址直接访问我们在堆内存中开辟的数组,然后改变数组,数组中的元素发生变化 方…...

Vue第1天:特性概览

文章目录 Vue.js 简介 Vue的特性 如何使用Vue 安装Vue 通过CDN引入 使用npm 创建Vue实例 结语 Vue.js 简介 Vue.js&#xff08;通常简称为Vue&#xff09;是一款流行的JavaScript框架&#xff0c;专注于构建用户界面。它的设计灵感来自于现代的JavaScript框架&#xf…...

C++语法基础知识面经汇总

背景&#xff1a;汇总了网上C常考的基础知识&#xff0c;方便复习 1&#xff0c;static关键字 static可以用于成员变量&#xff0c;或者成员函数。存储空间在静态存储区&#xff08;编译器会将其初始化为0&#xff0c;对应的存储空间直到程序执行结束才会释放&#xff09;&…...

AM@幂级数性质@幂级数和函数求解

文章目录 幂级数性质四则运算性质分析性质求解和函数例例 幂级数性质 和多项式有相似的性质本文介绍用幂级数的性质求解幂级数和函数的两个例子 四则运算性质 若幂级数 ∑ n 0 ∞ a n x n \sum_{n0}^{\infin}a_{n}x^{n} ∑n0∞​an​xn(1)的收敛半径为 R 1 R_1 R1​,和函数为…...

PHP低版本安全问题

目录 1、PHP弱类型问题 1.1 MD5、 SHA1 弱比较问题 1.2 数组 0 1&#xff09;函数无法处理数组&#xff0c;返回0 2&#xff09;strcmp 2、特殊字符串导致的问题 2.1 "ffifdyop" 与 md5(string,raw) 2.2 ereg函数漏洞&#xff1a;00 截断 3、正则匹配问…...

结构体——C语言初阶

一.结构体的声明&#xff1a; &#xff08;1&#xff09;结构的基础知识&#xff1a; 结构体是一种构造数据类型把不同类型的数据组合成一个整体结构体是一些值的集合&#xff0c;这些值称为成员变量。结构的每个成员可以是不同类型的变量需要注意的是&#xff0c;结构体是一种…...

基于django电影推荐系统

基于django电影推荐系统 摘要 该Django电影推荐系统是一个简单而基础的框架&#xff0c;旨在展示系统的基本组件。系统包括两个主要模型&#xff0c;即Movie和Rating&#xff0c;用于存储电影信息和用户评分。视图层包括展示电影列表和电影详情的功能&#xff0c;使用模板进行页…...

【问题处理】WPS提示不能启动此对象的源应用程序如何处理?

哈喽&#xff0c;大家好&#xff0c;我是雷工&#xff01; 最近在用WPS打开word文件中&#xff0c;插入的Excel附件时&#xff0c;无法打开&#xff0c;提示&#xff1a;“不能启动此对象的源应用程序”。 经过上网查找处理办法&#xff0c;尝试解决&#xff0c;现将解决过程记…...

UE 程序化网格 计算横截面

首先在构造函数内加上程序化网格&#xff0c;然后复制网格体到程序化网格组件上&#xff0c;将Static Mesh&#xff08;类型StaticMeshActor&#xff09;的静态网格体组件给到程序化网格体上 然后把StaticMesh&#xff08;类型为StaticMeshActor&#xff09;Instance暴漏出去 …...

【Spring】IoC容器的一些总结与补充

文章目录 1. 创建容器的两种方式相对路径导入绝对路径导入 2. 获取Bean的三种方式getBean后强转类型getBean内写明类别根据类别获取bean 3. 容器层次结构4. BeanFactory5. bean的总结6. 注入的总结 1. 创建容器的两种方式 相对路径导入 ApplicationContext ctx new ClassPat…...

Java GUI实现五子棋游戏

五子棋是一种双人对弈的棋类游戏&#xff0c;通常在棋盘上进行。棋盘为 1515 的方格&#xff0c;黑白双方各执棋子&#xff0c;轮流在棋盘的格点上落子&#xff0c;先在横、竖、斜线上形成五个相连的同色棋子者获胜。五子棋规则简单&#xff0c;易学难精&#xff0c;兼具攻防和…...

Python 集成 Nacos 配置中心

Python 集成 Nacos 配置中心 下载 Nacos 官方 pyhton 库 pip install nacos-sdk-python # 指定国内阿里云镜像源 pip3 install nacos-sdk-python -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com配置 Nacos 相关信息 Global:nacos:port: 8848…...

Debian 11 更新 Node.js 版本

发布于 2023-07-14 在 https://chenhaotian.top/debian/d-upd-nodejs/ 步骤 从 NodeSource 服务下载需要的 Node.js 安装脚本。注意更换版本号。当前的 LTS 版本是 18.x curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -现在可以直接从 apt 安装&#xff0…...

python 对图像进行聚类分析

import cv2 import numpy as np from sklearn.cluster import KMeans import time# 中文路径读取 def cv_imread(filePath, cv2_falgcv2.COLOR_BGR2RGB): cv_img cv2.imdecode(np.fromfile(filePath, dtypenp.uint8), cv2_falg) return cv_img# 自定义装饰器计算时间 def…...

程序员导航站

探路者 hello.alluniverse.vip 开发者导航 - Pro Developer网站导航 探路者是一款极简导航工具&#xff0c;致力于收录的每个站点都有其独特的作用。同时支持自定义导航&#xff0c;让用户快速实现个性化的导航站点。 特性概述 免费ChatGPT 装机必备 开发工具 Git精选项目 …...

BIO、NIO、AIO三者的区别及其应用场景(结合生活例子,简单易懂)

再解释三者之前我们需要先了解几个概念&#xff1a; 阻塞、非阻塞&#xff1a;是相较于线程来说的&#xff0c;如果是阻塞则线程无法往下执行&#xff0c;不阻塞&#xff0c;则线程可以继续往下 执行。同步、异步&#xff1a;是相较于IO来说的&#xff0c;同步需要等待IO操作完…...

RestClient

什么是RestClient RestClient 是 Elasticsearch 官方提供的 Java 低级 REST 客户端&#xff0c;它允许HTTP与Elasticsearch 集群通信&#xff0c;而无需处理 JSON 序列化/反序列化等底层细节。它是 Elasticsearch Java API 客户端的基础。 RestClient 主要特点 轻量级&#xff…...

java_网络服务相关_gateway_nacos_feign区别联系

1. spring-cloud-starter-gateway 作用&#xff1a;作为微服务架构的网关&#xff0c;统一入口&#xff0c;处理所有外部请求。 核心能力&#xff1a; 路由转发&#xff08;基于路径、服务名等&#xff09;过滤器&#xff08;鉴权、限流、日志、Header 处理&#xff09;支持负…...

【快手拥抱开源】通过快手团队开源的 KwaiCoder-AutoThink-preview 解锁大语言模型的潜力

引言&#xff1a; 在人工智能快速发展的浪潮中&#xff0c;快手Kwaipilot团队推出的 KwaiCoder-AutoThink-preview 具有里程碑意义——这是首个公开的AutoThink大语言模型&#xff08;LLM&#xff09;。该模型代表着该领域的重大突破&#xff0c;通过独特方式融合思考与非思考…...

C++ 基础特性深度解析

目录 引言 一、命名空间&#xff08;namespace&#xff09; C 中的命名空间​ 与 C 语言的对比​ 二、缺省参数​ C 中的缺省参数​ 与 C 语言的对比​ 三、引用&#xff08;reference&#xff09;​ C 中的引用​ 与 C 语言的对比​ 四、inline&#xff08;内联函数…...

【RockeMQ】第2节|RocketMQ快速实战以及核⼼概念详解(二)

升级Dledger高可用集群 一、主从架构的不足与Dledger的定位 主从架构缺陷 数据备份依赖Slave节点&#xff0c;但无自动故障转移能力&#xff0c;Master宕机后需人工切换&#xff0c;期间消息可能无法读取。Slave仅存储数据&#xff0c;无法主动升级为Master响应请求&#xff…...

select、poll、epoll 与 Reactor 模式

在高并发网络编程领域&#xff0c;高效处理大量连接和 I/O 事件是系统性能的关键。select、poll、epoll 作为 I/O 多路复用技术的代表&#xff0c;以及基于它们实现的 Reactor 模式&#xff0c;为开发者提供了强大的工具。本文将深入探讨这些技术的底层原理、优缺点。​ 一、I…...

管理学院权限管理系统开发总结

文章目录 &#x1f393; 管理学院权限管理系统开发总结 - 现代化Web应用实践之路&#x1f4dd; 项目概述&#x1f3d7;️ 技术架构设计后端技术栈前端技术栈 &#x1f4a1; 核心功能特性1. 用户管理模块2. 权限管理系统3. 统计报表功能4. 用户体验优化 &#x1f5c4;️ 数据库设…...

NXP S32K146 T-Box 携手 SD NAND(贴片式TF卡):驱动汽车智能革新的黄金组合

在汽车智能化的汹涌浪潮中&#xff0c;车辆不再仅仅是传统的交通工具&#xff0c;而是逐步演变为高度智能的移动终端。这一转变的核心支撑&#xff0c;来自于车内关键技术的深度融合与协同创新。车载远程信息处理盒&#xff08;T-Box&#xff09;方案&#xff1a;NXP S32K146 与…...

React从基础入门到高级实战:React 实战项目 - 项目五:微前端与模块化架构

React 实战项目&#xff1a;微前端与模块化架构 欢迎来到 React 开发教程专栏 的第 30 篇&#xff01;在前 29 篇文章中&#xff0c;我们从 React 的基础概念逐步深入到高级技巧&#xff0c;涵盖了组件设计、状态管理、路由配置、性能优化和企业级应用等核心内容。这一次&…...

node.js的初步学习

那什么是node.js呢&#xff1f; 和JavaScript又是什么关系呢&#xff1f; node.js 提供了 JavaScript的运行环境。当JavaScript作为后端开发语言来说&#xff0c; 需要在node.js的环境上进行当JavaScript作为前端开发语言来说&#xff0c;需要在浏览器的环境上进行 Node.js 可…...