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

基于jackson封装的json字符串与javaBean对象转换工具

文章目录

  • 一、概述
  • 二、编码实现
    • 1. pom文件引入组件
    • 2. 核心代码
  • 三、功能测试
    • 1. 测试文件
    • 2. 测试代码
  • 四,完整代码

一、概述

带有API接口交互的web项目开发过程中,json字符串与javaBean对象之间的相互转换是比较常见的需求,基于jackson ObjectMapper 实现的工具类较好的满足了此需求。

二、编码实现

1. pom文件引入组件

<dependency><groupId>org.springframework</groupId><artifactId>spring-webflux</artifactId><version>5.2.3.RELEASE</version></dependency><dependency><groupId>io.projectreactor.netty</groupId><artifactId>reactor-netty</artifactId><version>0.9.4.RELEASE</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.1</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.10.2</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.10</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.5.2</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency>

2. 核心代码

JsonBeanUtils


import java.io.IOException;import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;/*** JsonBean转换工具* * @author 00fly**/
public class JsonBeanUtils
{private static ObjectMapper objectMapper = new ObjectMapper();/*** bean转json字符串* * @param bean* @return* @throws IOException*/public static String beanToJson(Object bean)throws IOException{String jsonText = objectMapper.writeValueAsString(bean);return objectMapper.readTree(jsonText).toPrettyString();}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, Class<T> clazz)throws IOException{return objectMapper.readValue(jsonText, clazz);}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, JavaType javaType)throws IOException{return objectMapper.readValue(jsonText, javaType);}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, TypeReference<T> typeRef)throws IOException{return objectMapper.readValue(jsonText, typeRef);}
}

三、功能测试

1. 测试文件

jdbc.properties

druid.username=sa
druid.password=
druid.url=jdbc:h2:mem:hello;database_to_upper=false
druid.driverClassName=org.h2.Driver

data.json

{"code": 200,"message": "success","traceId": "fcd55497-864a-4d74-9db0-69a04655184f","data": {"list": [{"articleId": 135418954,"title": "java解析json复杂数据的两种思路","description": "萌新小明最近新开了CSDN博客,蠢蠢欲动,迫不及待的发表了几篇工作中积累下来的解决问题的涂鸦之作,看着访问量慢慢涨起来,心中暗暗窃喜。现在小明想每天23点记录一下每篇文章的访问量。。。","url": "https://blog.csdn.net/qq_16127313/article/details/135418954","type": 1,"top": false,"forcePlan": false,"viewCount": 828,"commentCount": 0,"editUrl": "https://editor.csdn.net/md?articleId=135418954","postTime": "2024-01-06 14:11:40","diggCount": 16,"formatTime": "前天 14:11","picList": ["https://img-blog.csdnimg.cn/direct/a409a0f4555c459fa05c00fd9ee0ea8c.png"],"collectCount": 19},{"articleId": 135244727,"title": "java lambda表达式训练题一","description": "Lambda 表达式,也可称为闭包,它是推动 Java 8 发布的最重要新特性。Lambda 允许把函数作为一个方法的参数(函数作为参数传递进方法中)。使用 Lambda 表达式可以使代码变的更加简洁紧凑。","url": "https://blog.csdn.net/qq_16127313/article/details/135244727","type": 1,"top": false,"forcePlan": false,"viewCount": 1238,"commentCount": 0,"editUrl": "https://editor.csdn.net/md?articleId=135244727","postTime": "2023-12-27 18:07:30","diggCount": 7,"formatTime": "2023.12.27","picList": ["https://img-blog.csdnimg.cn/direct/d59c68b950754e879914b5319cd1b53f.png"],"collectCount": 8},{"articleId": 135173565,"title": "二维码初体验 com.google.zxing 实现续 - web api封装","description": "在 二维码初体验 com.google.zxing 实现 我们实现了二维码的生成,但是大部分情况下,二维码的相关功能是作为API接口来提供服务的。我们下面便演示在springboot、Knife4j下封装api接口来实现二维码生成功能。如何使用下面的备份文件恢复成原始的项目代码,请移步查阅:神奇代码恢复工具-over-","url": "https://blog.csdn.net/qq_16127313/article/details/135173565","type": 1,"top": false,"forcePlan": false,"viewCount": 1904,"commentCount": 0,"editUrl": "https://editor.csdn.net/md?articleId=135173565","postTime": "2023-12-23 20:17:11","diggCount": 23,"formatTime": "2023.12.23","picList": ["https://img-blog.csdnimg.cn/direct/f0c994ca789a495a8c8c03d86d626f24.jpeg"],"collectCount": 23},{"articleId": 135167613,"title": "二维码初体验 com.google.zxing 实现","description": "Java 操作二维码的开源项目很多,如 SwetakeQRCode、BarCode4j、Zxing 等,这边以Zxing 为例进行介绍。选择需要生成QR原始文件,支持 “清除空白行及空格” 以减少二维码图片大小。支持输入文本内容,直接生成二维码代码结构QrCodeUI: 完整版本代码SimpleQrCodeUI:简化版本代码如何使用下面的备份文件恢复成原始的项目代码,请移步查阅:神奇代码恢复工具-over-","url": "https://blog.csdn.net/qq_16127313/article/details/135167613","type": 1,"top": false,"forcePlan": false,"viewCount": 1286,"commentCount": 0,"editUrl": "https://editor.csdn.net/md?articleId=135167613","postTime": "2023-12-23 13:52:23","diggCount": 6,"formatTime": "2023.12.23","picList": ["https://img-blog.csdnimg.cn/direct/d3eeac85857543869dce8967c570bdc4.jpeg"],"collectCount": 11},{"articleId": 135135799,"title": "【随笔】MD5加密字符串、文件apache、springframework实现","description": "【代码】【随笔】MD5加密字符串、文件commons-codec、springframework实现。","url": "https://blog.csdn.net/qq_16127313/article/details/135135799","type": 1,"top": false,"forcePlan": false,"viewCount": 1721,"commentCount": 0,"editUrl": "https://editor.csdn.net/md?articleId=135135799","postTime": "2023-12-21 17:29:54","diggCount": 9,"formatTime": "2023.12.21","picList": ["https://img-blog.csdnimg.cn/direct/dc26b7f1c731494f80c8c3b3badfa95d.jpeg"],"collectCount": 9}],"total": 72}
}

2. 测试代码


import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Properties;import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;import lombok.Data;
import lombok.extern.slf4j.Slf4j;/*** JsonBeanUtils测试*/
@Slf4j
public class JsonBeanUtilsTest
{static String jsonText;static Properties properties;static WebClient webClient;static String url;@BeforeAllpublic static void init(){try{properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("jdbc.properties"));jsonText = IOUtils.toString(new ClassPathResource("data.json").getURL(), StandardCharsets.UTF_8);webClient = WebClient.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)).build();url = "https://blog.csdn.net/community/home-api/v1/get-business-list?page=1&size=5&businessType=blog&username=qq_16127313";}catch (IOException e){log.error(e.getMessage(), e);}}@Testpublic void propsTest()throws IOException{String propsJson = JsonBeanUtils.beanToJson(properties);log.info("propsJson : {} ", propsJson);log.info("properties: {} ", JsonBeanUtils.jsonToBean(propsJson, Properties.class));}@Testpublic void beanToJson001()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);log.info("blogData: {} ", blogData);log.info("blogData: {} ", JsonBeanUtils.beanToJson(blogData));log.info("blogData.data: {} ", JsonBeanUtils.beanToJson(blogData.getData()));log.info("blogData.data.list: {} ", JsonBeanUtils.beanToJson(blogData.getData().getList()));}@Testpublic void beanToJson002()throws IOException{String resp = webClient.get().uri(url).acceptCharset(StandardCharsets.UTF_8).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(String.class).block();BlogData blogData = JsonBeanUtils.jsonToBean(resp, BlogData.class);String jsonText = JsonBeanUtils.beanToJson(blogData);log.info("blogData: {} ", blogData);log.info("jsonText: {} ", jsonText);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, JavaType javaType)* * @throws IOException*/@Testpublic void jsonToBean001()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr = JsonBeanUtils.beanToJson(blogData.getData().getList());// List<SubList>JavaType javaType = TypeFactory.defaultInstance().constructParametricType(List.class, SubList.class);List<SubList> dataEntitys = JsonBeanUtils.jsonToBean(jsonStr, javaType);log.info("dataEntitys: {} ", dataEntitys);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, TypeReference<T> typeRef)* * @throws IOException*/@Testpublic void jsonToBean002()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr = JsonBeanUtils.beanToJson(blogData.getData().getList());// List<SubList>TypeReference<List<SubList>> typeRef = new TypeReference<List<SubList>>(){};List<SubList> dataEntitys = JsonBeanUtils.jsonToBean(jsonStr, typeRef);log.info("dataEntitys: {} ", dataEntitys);}
}@Data
class BlogData
{private Integer code;private String message;private String traceId;private Record data;
}@Data
class Record
{private List<SubList> list;private Long total;
}@Data
class SubList
{String articleId;String title;String description;String url;Integer type;String top;String forcePlan;Long viewCount;Long commentCount;String editUrl;String postTime;Long diggCount;String formatTime;Object picList;Long collectCount;
}

四,完整代码

如何使用下面的备份文件恢复成原始的项目代码,请移步查阅:神奇代码恢复工具

//goto pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.fly</groupId><artifactId>base</artifactId><version>0.0.1</version><name>base</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version><skipTests>true</skipTests></properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-webflux</artifactId><version>5.2.3.RELEASE</version></dependency><dependency><groupId>io.projectreactor.netty</groupId><artifactId>reactor-netty</artifactId><version>0.9.4.RELEASE</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>2.12.1</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.10.2</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.10</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.5.2</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.10.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin></plugins></build>
</project>
//goto src\main\java\com\fly\core\utils\JsonBeanUtils.java
package com.fly.core.utils;import java.io.IOException;import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;/*** JsonBean转换工具* * @author 00fly**/
public class JsonBeanUtils
{private static ObjectMapper objectMapper = new ObjectMapper();/*** bean转json字符串* * @param bean* @return* @throws IOException*/public static String beanToJson(Object bean)throws IOException{String jsonText = objectMapper.writeValueAsString(bean);return objectMapper.readTree(jsonText).toPrettyString();}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, Class<T> clazz)throws IOException{return objectMapper.readValue(jsonText, clazz);}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, JavaType javaType)throws IOException{return objectMapper.readValue(jsonText, javaType);}/*** json字符串转bean* * @param jsonText* @return* @throws IOException*/public static <T> T jsonToBean(String jsonText, TypeReference<T> typeRef)throws IOException{return objectMapper.readValue(jsonText, typeRef);}
}
//goto src\main\resources\log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off" monitorInterval="0"><appenders><console name="Console" target="system_out"><patternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /></console></appenders><loggers><root level="INFO"><appender-ref ref="Console" /></root></loggers>
</configuration>
//goto src\test\java\com\fly\core\utils\JsonBeanUtilsTest.java
package com.fly.core.utils;import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Properties;import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;import lombok.Data;
import lombok.extern.slf4j.Slf4j;/*** JsonBeanUtils测试*/
@Slf4j
public class JsonBeanUtilsTest
{static String jsonText;static Properties properties;static WebClient webClient;static String url;@BeforeAllpublic static void init(){try{properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("jdbc.properties"));jsonText = IOUtils.toString(new ClassPathResource("data.json").getURL(), StandardCharsets.UTF_8);webClient = WebClient.builder().codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(-1)).build();url = "https://blog.csdn.net/community/home-api/v1/get-business-list?page=1&size=5&businessType=blog&username=qq_16127313";}catch (IOException e){log.error(e.getMessage(), e);}}@Testpublic void propsTest()throws IOException{String propsJson = JsonBeanUtils.beanToJson(properties);log.info("propsJson : {} ", propsJson);log.info("properties: {} ", JsonBeanUtils.jsonToBean(propsJson, Properties.class));}@Testpublic void beanToJson001()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);log.info("blogData: {} ", blogData);log.info("blogData: {} ", JsonBeanUtils.beanToJson(blogData));log.info("blogData.data: {} ", JsonBeanUtils.beanToJson(blogData.getData()));log.info("blogData.data.list: {} ", JsonBeanUtils.beanToJson(blogData.getData().getList()));}@Testpublic void beanToJson002()throws IOException{String resp = webClient.get().uri(url).acceptCharset(StandardCharsets.UTF_8).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(String.class).block();BlogData blogData = JsonBeanUtils.jsonToBean(resp, BlogData.class);String jsonText = JsonBeanUtils.beanToJson(blogData);log.info("blogData: {} ", blogData);log.info("jsonText: {} ", jsonText);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, JavaType javaType)* * @throws IOException*/@Testpublic void jsonToBean001()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr = JsonBeanUtils.beanToJson(blogData.getData().getList());// List<SubList>JavaType javaType = TypeFactory.defaultInstance().constructParametricType(List.class, SubList.class);List<SubList> dataEntitys = JsonBeanUtils.jsonToBean(jsonStr, javaType);log.info("dataEntitys: {} ", dataEntitys);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, TypeReference<T> typeRef)* * @throws IOException*/@Testpublic void jsonToBean002()throws IOException{BlogData blogData = JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr = JsonBeanUtils.beanToJson(blogData.getData().getList());// List<SubList>TypeReference<List<SubList>> typeRef = new TypeReference<List<SubList>>(){};List<SubList> dataEntitys = JsonBeanUtils.jsonToBean(jsonStr, typeRef);log.info("dataEntitys: {} ", dataEntitys);}
}@Data
class BlogData
{private Integer code;private String message;private String traceId;private Record data;
}@Data
class Record
{private List<SubList> list;private Long total;
}@Data
class SubList
{String articleId;String title;String description;String url;Integer type;String top;String forcePlan;Long viewCount;Long commentCount;String editUrl;String postTime;Long diggCount;String formatTime;Object picList;Long collectCount;
}
//goto src\test\resources\jdbc.properties
druid.username=sa
druid.password=
druid.url=jdbc:h2:mem:hello;database_to_upper=false
druid.driverClassName=org.h2.Driver
//goto src\test\resources\log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off" monitorInterval="0"><appenders><console name="Console" target="system_out"><patternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /></console></appenders><loggers><root level="INFO"><appender-ref ref="Console" /></root></loggers>
</configuration>

有任何问题和建议,都可以向我提问讨论,大家一起进步,谢谢!

-over-

相关文章:

基于jackson封装的json字符串与javaBean对象转换工具

文章目录 一、概述二、编码实现1. pom文件引入组件2. 核心代码 三、功能测试1. 测试文件2. 测试代码 四&#xff0c;完整代码 一、概述 带有API接口交互的web项目开发过程中&#xff0c;json字符串与javaBean对象之间的相互转换是比较常见的需求&#xff0c;基于jackson Objec…...

js中的数据类型

JavaScript 中有以下几种常见的数据类型&#xff1a; 基本类型&#xff08;原始类型&#xff09;&#xff1a; 字符串&#xff08;String&#xff09;&#xff1a;表示文本数据。数字&#xff08;Number&#xff09;&#xff1a;表示数值数据。布尔&#xff08;Boolean&#xf…...

vue3+vant+cropper.js实现移动端图片裁剪功能

一、前言 最近做项目中遇到一个需求&#xff0c;需要对海报图片按照一定的比例进行裁剪并上传到oss。一开始这个需求思路有两个&#xff0c;使用canvas原生或者寻找现成的第三方库&#xff0c;对比了一番觉得canvas实现时间耗费较长&#xff0c;且秉承着不重复造轮子的原则&am…...

springCould中的Bus-从小白开始【11】

目录 &#x1f9c2;1.Bus是什么❤️❤️❤️ &#x1f32d;2.什么是总线❤️❤️❤️ &#x1f953;3.rabbitmq❤️❤️❤️ &#x1f95e;4.新建模块3366❤️❤️❤️ &#x1f373;5.设计思想 ❤️❤️❤️ &#x1f37f;6.添加消息总线的支持❤️❤️❤️ &#x1f9…...

xshell和xftp

1.xshell和xftp的关系 Xftp和Xshell都是Xmanager Power Suite的组件&#xff0c;它们的功能和用途有所不同。 Xshell是一个用于MS Windows平台的强大的SSH、telnet和rlogin终端仿真软件&#xff0c;它使得用户能轻松和安全地从Windows PC上访问Unix/Linux主机。 Xftp是一个用…...

python for...else用法,一个实例就能让你明白

直接上代码&#xff0c;很简单&#xff0c;不用讲解吧&#xff0c;看不懂的话&#xff0c;就需要补充下基础知识了。 def funct2():for i in range(4):try:assert i>2print("success")breakexcept Exception as e:print(error)continueelse:print(循环不合预期)d…...

windows 设置ip命令bat脚本

您可以使用以下命令创建一个批处理文件&#xff08;.bat&#xff09;来添加IP地址&#xff1a; echo off set ipaddress set subnetmask set gatewaynetsh interface ip set address name"以太网" sourcestatic address%ipaddress% mask%subnetmask% gateway%gatewa…...

Openharmony 对应Android内存查看

众所周知&#xff0c;内存查看是一个很重要的部分&#xff0c;大多数情况&#xff0c;我们都是使用dumpsys的方法对android的内存进行查看&#xff0c;但是对于openharmony而言好像又不太一样了。 Android内存查看 命令行&#xff1a; adb shell dumpsys meminfo <packag…...

R语言【paleobioDB】——pbdb_interval():通过ID选择,返回一个地层年代段的基本信息

Package paleobioDB version 0.7.0 paleobioDB 包在2020年已经停止更新&#xff0c;该包依赖PBDB v1 API。 可以选择在Index of /src/contrib/Archive/paleobioDB (r-project.org)下载安装包后&#xff0c;执行本地安装。 Usage pbdb_interval (id, ...) Arguments 参数【id】…...

spring boot mybatis plus mapper如何自动注册到spring bean容器

##Import(AutoConfiguredMapperScannerRegistrar.class) ##注册MapperScannerConfigurer ##MapperScannerConfigurer.postProcessBeanDefinitionRegistry方法扫描注册mapper ##找到mapper候选者 ##过滤mapper 类 候选者 ##BeanDefinitionHolder注册到spring 容器...

What is `@PathVariable` does?

PathVariable 是SpringMVC中的注解&#xff0c;用于将HTTP请求的URI路径变量映射到Controller方法参数上。 当URL路径中包含占位符&#xff08;由大括号 {} 包围的部分&#xff09;时&#xff0c;可以使用此注解来绑定这些动态部分到方法参数。 使用样例 获取单个路径变量 …...

如何利用小程序介绍公司品牌形象?

企业小程序的建设对于现代企业来说已经成为了一项必不可少的工作。随着移动互联网的快速发展&#xff0c;越来越多的职场人士和创业老板希望通过小程序来提升企业形象&#xff0c;增强与用户的互动&#xff0c;实现更好的商业效果。在这个过程中&#xff0c;使用第三方制作平台…...

[C#]使用sdcb.paddleocr部署v4版本ocr识别模型

【官方框架地址】 https://github.com/sdcb/PaddleSharp 【算法介绍】 PaddleOCR&#xff0c;全称为PaddlePaddle OCR&#xff0c;是PaddlePaddle深度学习平台下的一款强大的光学字符识别工具。它利用深度学习技术&#xff0c;实现了高精度的文字识别&#xff0c;可以帮助用户…...

Echarts图表如何利用formatter自定义tooltip的内容和样式

在展示多数据图表的时候 有的时候需要图例也展示出一些内容来&#xff0c;例如官方这样子&#xff1a;鼠标悬停的时候展示该点数据 但是&#xff0c;官方提供的样式有时不适用所有的开发场景 我的项目需要实现鼠标悬停在某一点的时候&#xff0c;只展示该条线的数据&#xff0…...

Ceph源码分析-s->req_id = store->svc()->zone_utils->unique_id(req->id)

s->req_id store->svc()->zone_utils->unique_id(req->id); 涉及到指针和对象方法的调用。我会逐步为你解释这行代码的含义。 s->req_id ...; s 是一个指针&#xff0c;它指向一个结构或类。req_id 是该结构或类的一个成员变量。这行代码的意思是&#xff…...

Unity中的异步编程【7】——在一个异步方法里播放了animation动画,取消任务时,如何停止动画播放

用一个异步方法来播放一个动画&#xff0c;正常情况是&#xff1a;动画播放结束时&#xff0c;异步方法宣告结束。那如果我提前取消这个异步任务&#xff0c;那在这个异步方法里面&#xff0c;我要怎么停止播放呢&#xff1f;&#xff01; 一、播放animation动画的异步实现 1…...

vue3中ref和reactive联系与区别以及如何选择

vue3中ref和reactive区别与联系 区别 1、ref既可定义基本数据类型&#xff0c;也可以定义引用数据类型&#xff0c;reactive只能定义应用数据类型 2、ref在js中取响应值需要使用 .value&#xff0c;而reactive则直接取用既可 3、ref定义的对象通过.value重新分配新对象时依旧…...

面试宝典之spring框架常见面试题

F1、类的反射机制有啥用&#xff1f; &#xff08;1&#xff09;增加程序的灵活性&#xff0c;可扩展性&#xff0c;动态创建对象。 &#xff08;2&#xff09;框架必备&#xff0c;任何框架的封装都要用反射。&#xff08;框架的灵魂&#xff09; F2、获取Class对象的三种方…...

建筑垃圾处理行业分析:正在被越来越广泛的运用

建筑垃圾处理&#xff0c;是将固体废弃物作为再生资源重新利用的一种方式。建筑垃圾是在对建筑物实施新建、改建、扩建或者是拆除过程中产生的固体废弃物。建筑垃圾一般可分为建设废物、拆除垃圾及装修垃圾。因此建筑垃圾处理行业可以分为建设废物处理、拆除垃圾处理、装修垃圾…...

【DIY summaries on Linux】

DIY Linux summaries 1) difference between ways of creation file and edit files1.1) echoecho talk to yourself touch 1) difference between ways of creation file and edit files 1.1) echo ###) > echo talk to yourself touch...

蓝桥杯 2024 15届国赛 A组 儿童节快乐

P10576 [蓝桥杯 2024 国 A] 儿童节快乐 题目描述 五彩斑斓的气球在蓝天下悠然飘荡&#xff0c;轻快的音乐在耳边持续回荡&#xff0c;小朋友们手牵着手一同畅快欢笑。在这样一片安乐祥和的氛围下&#xff0c;六一来了。 今天是六一儿童节&#xff0c;小蓝老师为了让大家在节…...

3403. 从盒子中找出字典序最大的字符串 I

3403. 从盒子中找出字典序最大的字符串 I 题目链接&#xff1a;3403. 从盒子中找出字典序最大的字符串 I 代码如下&#xff1a; class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...

Element Plus 表单(el-form)中关于正整数输入的校验规则

目录 1 单个正整数输入1.1 模板1.2 校验规则 2 两个正整数输入&#xff08;联动&#xff09;2.1 模板2.2 校验规则2.3 CSS 1 单个正整数输入 1.1 模板 <el-formref"formRef":model"formData":rules"formRules"label-width"150px"…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

GitFlow 工作模式(详解)

今天再学项目的过程中遇到使用gitflow模式管理代码&#xff0c;因此进行学习并且发布关于gitflow的一些思考 Git与GitFlow模式 我们在写代码的时候通常会进行网上保存&#xff0c;无论是github还是gittee&#xff0c;都是一种基于git去保存代码的形式&#xff0c;这样保存代码…...

搭建DNS域名解析服务器(正向解析资源文件)

正向解析资源文件 1&#xff09;准备工作 服务端及客户端都关闭安全软件 [rootlocalhost ~]# systemctl stop firewalld [rootlocalhost ~]# setenforce 0 2&#xff09;服务端安装软件&#xff1a;bind 1.配置yum源 [rootlocalhost ~]# cat /etc/yum.repos.d/base.repo [Base…...

django blank 与 null的区别

1.blank blank控制表单验证时是否允许字段为空 2.null null控制数据库层面是否为空 但是&#xff0c;要注意以下几点&#xff1a; Django的表单验证与null无关&#xff1a;null参数控制的是数据库层面字段是否可以为NULL&#xff0c;而blank参数控制的是Django表单验证时字…...

【实施指南】Android客户端HTTPS双向认证实施指南

&#x1f510; 一、所需准备材料 证书文件&#xff08;6类核心文件&#xff09; 类型 格式 作用 Android端要求 CA根证书 .crt/.pem 验证服务器/客户端证书合法性 需预置到Android信任库 服务器证书 .crt 服务器身份证明 客户端需持有以验证服务器 客户端证书 .crt 客户端身份…...

JS红宝书笔记 - 3.3 变量

要定义变量&#xff0c;可以使用var操作符&#xff0c;后跟变量名 ES实现变量初始化&#xff0c;因此可以同时定义变量并设置它的值 使用var操作符定义的变量会成为包含它的函数的局部变量。 在函数内定义变量时省略var操作符&#xff0c;可以创建一个全局变量 如果需要定义…...