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

漳州网站建设今日特大新闻新事

漳州网站建设,今日特大新闻新事,做网站带来好处,揭阳制作公司网站在 Spring Boot 3 中整合 FastJSON 2 主要涉及到以下几个步骤,包括添加依赖、配置 FastJSON 作为 JSON 处理器等。下面是详细的步骤: 1. 添加依赖 首先,你需要在你的 pom.xml 文件中添加 FastJSON 2 的依赖。以下是 Maven 依赖的示例&#…

在 Spring Boot 3 中整合 FastJSON 2 主要涉及到以下几个步骤,包括添加依赖、配置 FastJSON 作为 JSON 处理器等。下面是详细的步骤:

1. 添加依赖

首先,你需要在你的 pom.xml 文件中添加 FastJSON 2 的依赖。以下是 Maven 依赖的示例:

<!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2-extension-spring6 -->
<dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2-extension-spring6</artifactId><version>2.0.53</version>
</dependency><!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
<dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.53</version>
</dependency>
2. 配置 FastJSON 作为 JSON 处理器

在 Spring Boot 3 中,默认的 JSON 处理器是 Jackson。如果你想使用 FastJSON 作为 JSON 处理器,你需要创建一个配置类来注册 FastJSON 的 HttpMessageConverter

import com.alibaba.fastjson2.support.config.FastJsonConfig;
import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;@Slf4j
@Configuration
public class Fastjson2Config implements WebMvcConfigurer {/*** Fastjson2Config* @author <a href="https://zhengkai.blog.csdn.net/">zhengkai.blog.csdn.net</a>*/@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();FastJsonConfig config = new FastJsonConfig();config.setDateFormat("yyyy-MM-dd HH:mm:ss");// 其他配置...converter.setFastJsonConfig(config);converter.setDefaultCharset(StandardCharsets.UTF_8);converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));converters.add(0, converter);log.info("Fastjson2 Initial Done");}
}
3. 使用 FastJSON2 进行 JSON 序列化和反序列化

在你的 Spring Boot 应用中,你可以直接使用 FastJSON 的 API 进行 JSON 的序列化和反序列化。例如:

import com.alibaba.fastjson2.JSON;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class SampleController {@GetMapping("/json")public String getJson() {MyObject obj = new MyObject();obj.setName("Test");obj.setValue(123);// 使用 FastJSON 进行序列化return JSON.toJSONString(obj);}public static class MyObject {private String name;private int value;// Getter 和 Setterpublic String getName() {return name;}public void setName(String name) {this.name = name;}public int getValue() {return value;}public void setValue(int value) {this.value = value;}}
}
4. 测试

启动你的 Spring Boot 应用,并访问 /json 路径,你应该能够看到 FastJSON 生成的 JSON 响应。

开源项目

SpringBoot3脚手架,基于SpringBoot3+Druid+PgSQL+MyBatisPlus13+FastJSON2+Lombok,启动web容器为Undertow(非默认tomcat),其他的请自行添加和配置。

https://gitee.com/moshowgame/MySpringBootAPIhttps://github.com/moshowgame/MySpringBootAPI

http://www.dtcms.com/wzjs/100325.html

相关文章:

  • 南京做网站哪家好石家庄网站seo
  • 一级域名 二级域名 目录网站推广电商网站
  • 万网如何上传网站互联网推广招聘
  • 网站建设的市场有多大网站建设制作专业
  • 太原网站建设地图常见的网络营销平台有哪些
  • 网站维护 静态页面服务器租用
  • 部门网站建设seo分析
  • 公司网站推广如何做现在如何进行网上推广
  • 东莞做个网站百度网盘优化
  • 建设部网站证书查询网页设计工作室长沙
  • wordpress 获得当前url重庆seo推广公司
  • 加强机关网站内容建设今日热点
  • 残疾人无障碍网站怎么做武汉网络关键词排名
  • 男人和女人做羞羞的免费网站郴州网站建设网络推广渠道
  • 58同城招聘 招聘网许昌seo推广
  • 手机网站与PC网站长春seo排名扣费
  • 中国建设银行东莞市网站提高工作效率的工具
  • 网站视频主持人网临沂网站建设公司哪家好
  • 东莞品牌网站设计公司网址如何下载视频
  • 安卓毕业设计代做网站青岛seo关键词
  • 罗马尼亚网站后缀长沙网站开发
  • 湖南建网站设计网络推广方案
  • 虚拟主机如何做网站国外免费建站网站搭建
  • 网站制作加教程视频网站制作培训
  • 建设网站好公司哪家好手机导航下载2022新版
  • 企业为什么做网站 图片国际军事新闻
  • 网站每天一条推送怎么做的优化网络推广外包
  • 山西住房和城乡建设厅网站优化方法
  • 东莞58同城做网站电话zac博客seo
  • 已经有了域名怎么做网站seo排名优化网站