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

Jackson详解

文章目录

  • 一、Jackson介绍
  • 二、基础序列化和反序列化
    • 1、快速入门
    • 2、序列化API
    • 3、反序列化API
    • 4、常用配置
  • 三、常用注解
    • 1、@JsonProperty
    • 2、@JsonAlias
    • 3、@JsonIgnore
    • 4、@JsonIgnoreProperties
    • 5、@JsonFormat
    • 6、@JsonPropertyOrder
  • 四、高级特性
    • 1、处理泛型
      • 1.1、反序列化List泛型
      • 1.2、反序列化Map泛型
    • 2、自定义序列化和反序列化

一、Jackson介绍

  • Jackson库的核心功能是将Java对象转换为json字符串(序列化)以及将json字符串转换为Java对象(反序列化)
  • SpringMVC默认json解析器便是Jackson

与其他Java的json的框架相比

  • Jackson 解析的json文件速度比较快
  • Jackson 运行时占用内存比较,性能比较好
  • Jackson 有灵活的API,可以很容易进行扩展和定制

核心模块由三部分组成

  • jackson-core,核心包,提供基于"流模式"解析的相关API(JsonPaser和JsonGenerator),生成和解析json
  • jackson-annotations,注解包,提供标准注解功能
  • jackson-databind ,数据绑定包,提供基于"对象绑定"解析的相关API(ObjectMapper)和"树模型"解析的相关API(JsonNode)

其中 jackson-databind内部依赖了jackson-annotations与ackson-core,故只导入jackson-databind即可

<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.11.0</version>
</dependency>

二、基础序列化和反序列化

  • ObjectMapper是Jackson序列化和反序列化的核心类,提供了许多用于定制序列化和反序列化的方法和配置选项
  • 默认情况下,ObjectMapper在序列化对象时,将实体所有的字段一一序列化,无论这些字段是否有值,是否为null
  • 注意:如果实体的某个字段没有提供getter方法,则该字段不会被序列化
  • ObjectMapper主要用于对Java对象(比如 POJO、List、Set、Map等等)进行序列化与反序列化

1、快速入门

 @Testpublic void test1() throws JsonProcessingException {ObjectMapper objectMapper = new ObjectMapper();User user = new User();user.setAge(20);user.setBirthday(new Date());user.setName("张三");user.setAddress(null);// 序列化String jsonString = objectMapper.writeValueAsString(user);System.out.println("序列化字符串:" + jsonString);// 反序列化User userFromJson = objectMapper.readValue(jsonString, User.class);System.out.println("反序列化结果:" + userFromJson);}

输出结果:

序列化字符串:{"age":20,"name":"张三","birthday":1721266913536,"address":null}
反序列化结果:User(age=20, name=张三, birthday=Thu Jul 18 09:41:53 CST 2024, address=null)

2、序列化API

  • String writeValueAsString(Object value)(最常用)
    • 将任何Java对象()如 POJO、List、Set、Map等)序列化为json字符串
    • 如果对象中某个属性的值为null,则默认也会序列化为null
    • 如果value为null,返回序列化的结果也返回null
  • byte[] writeValueAsBytes(Object value)
    • 将Java对象序列化为字节数组
  • writeValue(File resultFile, Object value)
    • 将Java对象序列化并输出指定文件
  • writeValue(OutputStream out, Object value)
    • 将Java对象序列化并输出到指定字节输出流
@Test
public void test2() throws IOException {ObjectMapper objectMapper = new ObjectMapper();User user = new User();user.setAge(20);user.setBirthday(new Date());user.setName("张三");user.setAddress(null);// 序列化bytbyte[] bytes = objectMapper.writeValueAsBytes(user);System.out.println("序列化字节数组:" + new String(bytes));// 序列化到文件objectMapper.writeValue(new File("/Users/xuchang/Documents/json.txt"), user);
}

输出结果:

在这里插入图片描述

3、反序列化API

  • T readValue(String content, Class valueType)(最常用)
    • 从给定的json字符串反序列化为Java对象
    • valueType表示反序列化的任何Class对象(如 POJO、List、Set、Map等)
    • content为空或者为null,都会报错
  • T readValue(byte[] src, Class valueType)
    • 将json内容的字节数组反序列化为Java对象
  • T readValue(File src, Class valueType)
    • 将本地json内容的文件反序列化为Java对象
  • T readValue(InputStream src, Class valueType)
    • 将json内容的字节输入流反序列化为Java对象
  • T readValue(Reader src, Class valueType)
    • 将json内容的字符输入流反序列化为Java对象
  • T readValue(URL src, Class valueType)
    • 通过网络url地址将json内容反序列化为Java对象

4、常用配置

private static final ObjectMapper objectMapper;static {// 创建ObjectMapper对象objectMapper = new ObjectMapper();// configure方法 配置一些需要的参数// 转换为格式化的json 显示出来的格式美化objectMapper.enable(SerializationFeature.INDENT_OUTPUT);// 序列化的时候序列对象的那些属性// JsonInclude.Include.NON_DEFAULT 属性为默认值不序列化// JsonInclude.Include.ALWAYS      所有属性// JsonInclude.Include.NON_EMPTY   属性为 空(“”) 或者为 NULL 都不序列化// JsonInclude.Include.NON_NULL    属性为NULL 不序列化objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);// 反序列化时,遇到未知属性会不会报错// true - 遇到没有的属性就报错// false - 没有的属性不会管,不会报错objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);// 如果是空对象的时候,不抛异常objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);// 忽略 transient 修饰的属性objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);// 去除默认时间戳格式objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);// 设置为中国北京时区objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));// 序列化日期格式 Date类型格式化objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));// 处理java8不同时间类型JavaTimeModule module = new JavaTimeModule();module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));module.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));module.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(("HH:mm:ss"))));module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));module.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));module.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));// 序列换成json时,将所有的long变成string(因为js中得数字类型不能包含所有的java long值)module.addSerializer(Long.TYPE, ToStringSerializer.instance);module.addSerializer(Long.class, ToStringSerializer.instance);objectMapper.registerModule(module);
}@Test
public void testObjectMapper() throws JsonProcessingException {User user = new User();user.setId(1770376103094779915L);user.setAge(20);user.setBirthday(new Date());user.setName("张三");user.setAddress(null);user.setLocalDateTime(LocalDateTime.now());// 序列化String jsonString = objectMapper.writeValueAsString(user);System.out.println("序列化字符串:" + jsonString);// 注意这里添加不存在的属性hobby,反序列化不会报错jsonString = "{\"id\":1770376103094779915,\"age\":20,\"name\":\"张三\",\"birthday\":\"2024-07-19 11:02:19\",\"hobby\":\"打篮球\"}";// 反序列化User userFromJson = objectMapper.readValue(jsonString, User.class);System.out.println("反序列化结果:" + userFromJson);
}
@Data
public class User {private Long id;private Integer age;private String name;private Date birthday;private String address;private LocalDateTime localDateTime;
}

输出结果:

序列化字符串:{"id" : "1770376103094779915","age" : 20,"name" : "张三","birthday" : "2024-07-19 14:27:48","localDateTime" : "2024-07-19 14:27:48"
}
反序列化结果:User(id=1770376103094779915, age=20, name=张三, birthday=Fri Jul 19 11:02:19 CST 2024, address=null, localDateTime=null)

三、常用注解

1、@JsonProperty

  • 用于在Java对象的属性和json字段之间建立映射关系
    • value:用于指定json属性的名称,当Java属性和json属性名称不一致时使用
    • index:指示此属性的数字索引的属性
    • access:用于指定该属性的访问方式
      • JsonAccess.READ_ONLY(只读-序列化可见)
      • JsonAccess.WRITE_ONLY(只写-反序列化可见)
      • JsonAccess.READ_WRITE(可读可写)
@Test
public void test3() throws JsonProcessingException {ObjectMapper objectMapper = new ObjectMapper();User user = new User();user.setAge(18);user.setName("张三");user.setAddress("北京");user.setBirthday(new Date());// 序列化为json字符串String jsonString = objectMapper.writeValueAsString(user);System.out.println(jsonString);// 反序列化为对象String userJson = "{\"age\":18,\"user_address\":\"北京\",\"user_birthday\":1721309276459,\"user_name\":\"张三\"}";User userValue = objectMapper.readValue(userJson, User.class);System.out.println(userValue);
}@Data
public class User {@JsonProperty(index = 0)private Integer age;@JsonProperty(value = "user_name", access = JsonProperty.Access.READ_ONLY, index = 3)private String name;@JsonProperty(value = "user_birthday", access = JsonProperty.Access.WRITE_ONLY, index = 2)private Date birthday;@JsonProperty(value = "user_address", access = JsonProperty.Access.READ_WRITE, index = 1)private String address;
}

输出结果:

{"age":18,"user_address":"北京","user_name":"张三"}
User(age=18, name=null, birthday=Thu Jul 18 21:27:56 CST 2024, address=北京)
  • 序列化属性名称及value设置的名称
  • 序列化根据index属性排序,反序列化还是类自上而下的顺序
  • 只读属性可以序列化,只写属性可以反序列化(读和写是相对内存中对象来理解的)

2、@JsonAlias

  • 在反序列化的时候可以让Bean的属性接收多个json字段的名称
@Test
public void test4() throws JsonProcessingException {ObjectMapper objectMapper = new ObjectMapper();// 反序列化为对象String userJson = "{\"age\":18,\"address\":\"北京\",\"birthday\":1721309276459,\"nick_name\":\"张三\"}";User userValue = objectMapper.readValue(userJson, User.class);System.out.println(userValue);
}@Data
public class User {private Integer age;@JsonAlias(value = {"nick_name","vip_name"})private String name;private Date birthday;private String address;
}

输出结果:

User(age=18, name=张三, birthday=Thu Jul 18 21:27:56 CST 2024, address=北京)

3、@JsonIgnore

  • 序列化时将java bean中的一些属性忽略掉,序列化和反序列化都受影响
  • 一般标记在属性或者方法上,返回的json数据即不包含该属性
@Test
public void test5() throws JsonProcessingException {ObjectMapper objectMapper = new ObjectMapper();User user = new User();user.setAge(18);user.setName("张三");user.setAddress("北京");user.setBirthday(new Date());// 序列化为json字符串String jsonString = objectMapper.writeValueAsString(user);System.out.println(jsonString);// 反序列化为对象String userJson = "{\"age\":18,\"address\":\"北京\",\"birthday\":1721309276459,\"name\":\"张三\"}";User userValue = objectMapper.readValue(userJson, User.class);System.out.println(userValue);
}
@Data
public class User {@JsonIgnoreprivate Integer age;@JsonIgnoreprivate String name;private Date birthday;private String address;
}

输出结果:

{"birthday":1721310730459,"address":"北京"}
User(age=null, name=null, birthday=Thu Jul 18 21:27:56 CST 2024, address=北京)

4、@JsonIgnoreProperties

  • 序列化时将java bean中的一些属性忽略掉,序列化和反序列化都受影响
@Data
@JsonIgnoreProperties({"age", "name"})
public class User {private Integer age;private String name;private Date birthday;private String address;
}

5、@JsonFormat

  • 时间格式化注解
    • pattern: 表示日期的格式,比如:yyyy-MM-dd HH:mm:ss
    • timezone: 默认是GMT,中国需要GMT+8
      • 中国时间(Asia/Shanghai) = 格林尼治时间(GMT)+ 8
      • 格林尼治时间(GMT) = 世界协调时间(UTC) + 0
@Test
public void test6() throws JsonProcessingException {ObjectMapper objectMapper = new ObjectMapper();User user = new User();user.setAge(18);user.setName("张三");user.setAddress("北京");user.setBirthday(new Date());// 序列化为json字符串String jsonString = objectMapper.writeValueAsString(user);System.out.println(jsonString);// 反序列化为对象User userValue = objectMapper.readValue(jsonString, User.class);System.out.println(userValue);
}
@Data
public class User {private Integer age;private String name;@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")private Date birthday;private String address;
}

输出结果:

{"age":18,"name":"张三","birthday":"2024-07-18 22:10:36","address":"北京"}
User(age=18, name=张三, birthday=Thu Jul 18 22:10:36 CST 2024, address=北京)

6、@JsonPropertyOrder

  • 用于指定实体生成json时的属性顺序
// 自定义顺序
@JsonPropertyOrder({"name", "age", "address"})
//按字母排序
@JsonPropertyOrder(alphabetic=true)

四、高级特性

1、处理泛型

1.1、反序列化List泛型

  • 可以使用CollectionType类型反序列化,也可以构造TypeReference反序列化
@Test
public void test7() throws JsonProcessingException {ObjectMapper mapper = new ObjectMapper();CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, User.class);// 造数据List<User> list = new ArrayList<>();for (int i = 0; i < 3; i++) {User user = new User();user.setId((long) i);user.setName("张三" + i);list.add(user);}System.out.println("序列化");String jsonInString = mapper.writeValueAsString(list);System.out.println(jsonInString);System.out.println("反序列化:使用 javaType");List<User> userList1 = mapper.readValue(jsonInString, javaType);System.out.println(userList1);System.out.println("反序列化:使用 TypeReference");List<User> userList2 = mapper.readValue(jsonInString, new TypeReference<List<User>>() {});System.out.println(userList2);
}
@Data
public class User {private Long id;private String name;
}

输出:

序列化
[{"id":0,"name":"张三0"},{"id":1,"name":"张三1"},{"id":2,"name":"张三2"}]
反序列化:使用 javaType
[User(id=0, name=张三0), User(id=1, name=张三1), User(id=2, name=张三2)]
反序列化:使用 TypeReference
[User(id=0, name=张三0), User(id=1, name=张三1), User(id=2, name=张三2)]

1.2、反序列化Map泛型

  • 可以使用MapType类型反序列化,也可以构造TypeReference反序列化
@Test
public void test8() throws IOException {ObjectMapper mapper = new ObjectMapper();//第二参数是 map 的 key 的类型,第三参数是 map 的 value 的类型MapType javaType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, User.class);// 造数据Map<String, User> map = new HashMap<>();for (int i = 0; i < 3; i++) {User user = new User();user.setId((long) i);user.setName("张三" + i);map.put("key" + i, user);}System.out.println("序列化");String jsonInString = mapper.writeValueAsString(map);System.out.println(jsonInString);System.out.println("反序列化: 使用 javaType");Map<String, User> userMap1 = mapper.readValue(jsonInString, javaType);System.out.println(userMap1);System.out.println("反序列化: 使用 TypeReference");Map<String, User> userMap2 = mapper.readValue(jsonInString, new TypeReference<Map<String, User>>() {});System.out.println(userMap2);
}

输出结果:

序列化
{"key1":{"id":1,"name":"张三1"},"key2":{"id":2,"name":"张三2"},"key0":{"id":0,"name":"张三0"}}
反序列化: 使用 javaType
{key1=User(id=1, name=张三1), key2=User(id=2, name=张三2), key0=User(id=0, name=张三0)}
反序列化: 使用 TypeReference
{key1=User(id=1, name=张三1), key2=User(id=2, name=张三2), key0=User(id=0, name=张三0)}

2、自定义序列化和反序列化

  • 序列化类继承抽象类JsonSerializer,需要的字段或类上使用@JsonSerialize注解
  • 反序列化类继承抽象类JsonDeserializer,需要的字段或类上使用@JsonDeserialize注解
public class LongSerializer extends JsonSerializer<Long> {@Overridepublic void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {gen.writeString(value.toString());}
}@Data
public class User {@JsonSerialize(using = LongSerializer.class)private Long id;private String name;
}

相关文章:

Jackson详解

文章目录 一、Jackson介绍二、基础序列化和反序列化1、快速入门2、序列化API3、反序列化API4、常用配置 三、常用注解1、JsonProperty2、JsonAlias3、JsonIgnore4、JsonIgnoreProperties5、JsonFormat6、JsonPropertyOrder 四、高级特性1、处理泛型1.1、反序列化List泛型1.2、反…...

【算法】字符串

快乐的流畅&#xff1a;个人主页 个人专栏&#xff1a;《算法神殿》《数据结构世界》《进击的C》 远方有一堆篝火&#xff0c;在为久候之人燃烧&#xff01; 文章目录 引言一、最长公共前缀二、最长回文子串三、二进制求和四、字符串相乘 引言 字符串题&#xff0c;大多数是模…...

Python酷库之旅-第三方库Pandas(037)

目录 一、用法精讲 116、pandas.Series.div方法 116-1、语法 116-2、参数 116-3、功能 116-4、返回值 116-5、说明 116-6、用法 116-6-1、数据准备 116-6-2、代码示例 116-6-3、结果输出 117、pandas.Series.truediv方法 117-1、语法 117-2、参数 117-3、功能 …...

iOS 左滑返回事件的控制

0x00 视图结构 1-根视图 1.1-控制器A 1.1.1-控制器B 1.1.1.1-控制器C 0x01 控制 通过设置 self.navigationController.interactivePopGestureRecognizer.enabled 为 YES 或 NO 来控制当面界面&#xff0c;是否能左滑返回 在 控制器B 的生命周期方法内&#xff0c;设置属性 s…...

= null 和 is null;SQL中关于NULL处理的4个陷阱;三值逻辑

一、概述 1、NULL参与的所有的比较和算术运算符(>,,<,<>,<,>,,-,*,/) 结果为unknown&#xff1b; 2、unknown的逻辑运算(AND、OR、NOT&#xff09;遵循三值运算的真值表&#xff1b; 3、如果运算结果直接返回用户&#xff0c;使用NULL来标识unknown 4、如…...

拖拽上传(预览图片)

需求 点击上传图片&#xff0c;或直接拖拽图片到红色方框里面也可上传图片&#xff0c;上传后预览图片 效果 实现 <!DOCTYPE html> <html lang"zh-cn"><head><meta charset"UTF-8"><meta name"viewport" content&…...

Oracle 12c新特性 In-Memory Column Store

Oracle 12c引入了一项重要的特性——In-Memory Column Store&#xff08;简称IM或In-Memory&#xff09;&#xff0c;这一特性极大地提升了数据库在处理分析型查询时的性能。以下是关于Oracle 12c In-Memory特性的详细介绍&#xff1a; 一、基本概念 In-Memory Column Store&…...

【数据结构】二叉树———Lesson2

Hi~&#xff01;这里是奋斗的小羊&#xff0c;很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~~ &#x1f4a5;&#x1f4a5;个人主页&#xff1a;奋斗的小羊 &#x1f4a5;&#x1f4a5;所属专栏&#xff1a;C语言 &#x1f680;本系列文章为个人学习…...

mongodb数据导出与导入

一、先去检查mongodump mongodump --version 如果报 mongodump version: built-without-version-string 或者其他的较老的版本&#xff0c;直接去下载最新的【传送门】 【以Ubuntu18.04为例】 安装工具 假设你下载的是 .tgz 文件&#xff08;适用于 Linux 系统&#xff09;&am…...

电路学习——经典运放电路之滞回比较器(施密特触发器)(2024.07.18)

参考链接1: 电子设计教程29&#xff1a;滞回比较器&#xff08;施密特触发器&#xff09; 参考链接2: 滞回比较器电路详细分析 参考链接3: 比较器精髓&#xff1a;施密特触发器&#xff0c;正反馈的妙用 参考链接4: 比较器反馈电阻选多大&#xff1f;理解滞后效应&#xff0c;轻…...

NVIDIA Container Toolkit 安装与配置帮助文档(Ubuntu,Docker)

NVIDIA Container Toolkit 安装与配置帮助文档(Ubuntu,Docker) 本文档详细介绍了在 Ubuntu Server 22.04 上使用 Docker 安装和配置 NVIDIA Container Toolkit 的过程。 概述 NVIDIA 容器工具包使用户能够构建和运行 GPU 加速容器。即可以在容器中使用NVIDIA显卡。 架构图如…...

JavaWeb day01-HTML入门

Web前端 课程安排 HTML、CSS简介 HTML快速入门 实现标题排版 新闻标题样式...

驱动框架——CMSIS第一部分 RTE驱动框架介绍

一、介绍CMISIS 什么是CMSIS&#xff08;cortex microcontrol software interface standard一种软件标准接口&#xff09;&#xff0c;官网地址&#xff1a;https://arm-software.github.io/CMSIS_6/latest/General/index.html 包含的core、driver、RTOS、dsp、nn等部分&…...

Debezium日常分享系列之:Debezium2.7版本PostgreSQL数据库连接器

Debezium日常分享系列之:Debezium2.7版本PostgreSQL数据库连接器 一、概述二、连接器的工作原理安全快照初始快照的默认工作流程行为临时快照触发临时增量快照触发临时阻塞快照增量快照增量快照流程Debezium 如何解决具有相同主键的记录之间的冲突快照窗口触发增量快照具有附加…...

保障信息系统安全保护等级调整期间的安全性

保障信息系统安全保护等级调整期间的安全性&#xff1a; 策略与实践 在当今数字化时代&#xff0c;信息系统已成为企业和组织运营的核心支撑。为了适应不断变化的业务需求和安全威胁环境&#xff0c;信息系统安全保护等级的调整成为必要之举。然而&#xff0c;这一调整过程可能…...

实战:shell编程之全量命令练习

概叙 槽点~~~~~~~&#xff01; 往期shell相关文章回顾&#xff0c;有兴趣的可以自行阅读和练习。 科普文&#xff1a;一文搞懂Vim-CSDN博客 科普文&#xff1a;jvm笔记-CSDN博客 科普文&#xff1a;一天学会shell编程-CSDN博客 科普文&#xff1a;Linux服务器巡检小结_lin…...

在 CentOS 7 上编译安装 Python 3.11

安装必要的依赖 首先&#xff0c;你需要安装一些开发工具和库&#xff0c;以便编译 Python 和 OpenSSL&#xff1a; yum -y groupinstall "Development tools" yum install -y wget gcc-c pcre pcre-devel zlib zlib-devel libffi-devel zlib1g-dev openssl-devel …...

Qt 4.8.7 + MSVC 中文乱码问题深入分析

此问题很常见&#xff0c;然而网上关于此问题的分析大多不够深刻&#xff0c;甚至有错误&#xff1b;加之Qt5又更改了一些编码策略&#xff0c;而很多文章并未提及版本问题&#xff0c;或是就算提了&#xff0c;读者也不重视。这些因素很容易让读者产生误导。今日我彻底研究透了…...

IDEA的常见代码模板的使用

《IDEA破解、配置、使用技巧与实战教程》系列文章目录 第一章 IDEA破解与HelloWorld的实战编写 第二章 IDEA的详细设置 第三章 IDEA的工程与模块管理 第四章 IDEA的常见代码模板的使用 第五章 IDEA中常用的快捷键 第六章 IDEA的断点调试&#xff08;Debug&#xff09; 第七章 …...

arcgis怎么选取某个指定区域地方的数据,比如从全国乡镇数据选取长沙市乡镇数据

一共5个步骤&#xff0c;没一句废话&#xff0c;耐心看完。看完你就会在任何软件选取指定范围的数据了。 一、如图&#xff0c;先将数据加载到arcgis里面&#xff0c;我们要选取里面长沙市的范围数据。 二、选取长沙市的语句 “市” like ‘长沙%’ 切记&#xff0c;切记&…...

测试微信模版消息推送

进入“开发接口管理”--“公众平台测试账号”&#xff0c;无需申请公众账号、可在测试账号中体验并测试微信公众平台所有高级接口。 获取access_token: 自定义模版消息&#xff1a; 关注测试号&#xff1a;扫二维码关注测试号。 发送模版消息&#xff1a; import requests da…...

谷歌浏览器插件

项目中有时候会用到插件 sync-cookie-extension1.0.0&#xff1a;开发环境同步测试 cookie 至 localhost&#xff0c;便于本地请求服务携带 cookie 参考地址&#xff1a;https://juejin.cn/post/7139354571712757767 里面有源码下载下来&#xff0c;加在到扩展即可使用FeHelp…...

遍历 Map 类型集合的方法汇总

1 方法一 先用方法 keySet() 获取集合中的所有键。再通过 gey(key) 方法用对应键获取值 import java.util.HashMap; import java.util.Set;public class Test {public static void main(String[] args) {HashMap hashMap new HashMap();hashMap.put("语文",99);has…...

关于nvm与node.js

1 安装nvm 安装过程中手动修改 nvm的安装路径&#xff0c; 以及修改 通过nvm安装node后正在使用的node的存放目录【这句话可能难以理解&#xff0c;但接着往下看你就了然了】 2 修改nvm中settings.txt文件配置 nvm安装成功后&#xff0c;通常在该文件中会出现以下配置&…...

Robots.txt 文件

什么是robots.txt&#xff1f; robots.txt 是一个位于网站根目录下的文本文件&#xff08;如&#xff1a;https://example.com/robots.txt&#xff09;&#xff0c;它用于指导网络爬虫&#xff08;如搜索引擎的蜘蛛程序&#xff09;如何抓取该网站的内容。这个文件遵循 Robots…...

三体问题详解

从物理学角度&#xff0c;三体问题之所以不稳定&#xff0c;是因为三个天体在万有引力作用下相互作用&#xff0c;形成一个非线性耦合系统。我们可以从牛顿经典力学出发&#xff0c;列出具体的运动方程&#xff0c;并说明为何这个系统本质上是混沌的&#xff0c;无法得到一般解…...

OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别

OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别 直接训练提示词嵌入向量的核心区别 您提到的代码: prompt_embedding = initial_embedding.clone().requires_grad_(True) optimizer = torch.optim.Adam([prompt_embedding...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

稳定币的深度剖析与展望

一、引言 在当今数字化浪潮席卷全球的时代&#xff0c;加密货币作为一种新兴的金融现象&#xff0c;正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而&#xff0c;加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下&#xff0c;稳定…...

算法笔记2

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