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

漳州网站建设百度指数分析

漳州网站建设,百度指数分析,网页设计心得体会1500,网站建设600元全包在 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/217150.html

相关文章:

  • 网站建设 更新 维护重庆镇海seo整站优化价格
  • wordpress手机维护惠州seo计费管理
  • 做网站和编程序快速网站推广
  • 网站系统开发怎么做免费的域名和网站
  • wordpress 本地头像清远seo
  • 德阳做网站的公司百度客服人工电话
  • wordpress手机网站模版百度推广年费多少钱
  • 网站专题怎么做广州广告公司
  • 个人网站可以做百度推广吗搜索引擎营销的基本流程
  • 用vs2008做的网站前台脚本是什么企业seo
  • 番禺卫生人才网长沙seo推广公司
  • 电商网站开发csdn分享学seo推广
  • 宁夏建设职业技术学院官方网站百度软件中心下载
  • 甘肃网站建设费用seo排名专业公司
  • 书画网站免费源码产品营销策略怎么写
  • 学生处网站建设工作总结求个网站
  • 网站的开发环境怎么写国际新闻最新消息今天
  • 手机音乐网站源码百度电话号码
  • 阿里云香港节点做的网站西安百度首页优化
  • 合肥 做网站的百度产品
  • 望城区建设局网站谷歌搜索引擎入口2021
  • 电器网站建设策划书东莞推广
  • 夺宝网站开发营销推广型网站
  • 汕头百度关键词搜索seo关键词教程
  • 怎么做类似清风dj网站域名历史查询工具
  • 南通通州区城乡建设局网站1688精品货源网站入口
  • 怎么用腾讯云服务器做网站网站怎么制作
  • nodejs做网站容易被攻击吗南平网站seo
  • 大学精神文明建设专题网站长沙网站seo哪家公司好
  • 做软件用什么编程语言seo外包服务公司