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

怎么看网站开发的技术百度交易平台

怎么看网站开发的技术,百度交易平台,国家企业信息公示系统全国,手机网站分享js代码常用json数据格式化有: 1、Long转String防止JS精度丢失 2、时间日期类型的统一格式化 可以使用注解实现json数据格式化: /*** 主键 将long使用String序列化*/JsonSerialize(using ToStringSerializer.class)JSONField(serializeUsing ToStringSeriali…

常用json数据格式化有:
1、Long转String防止JS精度丢失
2、时间日期类型的统一格式化

可以使用注解实现json数据格式化:

    /*** 主键 将long使用String序列化*/@JsonSerialize(using = ToStringSerializer.class)@JSONField(serializeUsing = ToStringSerializer.class)private Long id;/*** 时间 日期类格式 注解*/@JSONField(format = "yyyy-MM-dd HH:mm:ss")@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")private LocalDateTime createTime;

使用注解方式非常繁重,直接在WebMvcConfigurer统一配置实现接口数据响应的格式化输出。

springboot 统一格式化输出简单实现方式;
1、Jackson中ObjectMapper序列化配置

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;/*** 全局 jackson 序列化配置** @author Yang douya* @date 2025/5/29 9:13*/
@Slf4j
@Configuration
public class JacksonConfig {public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";//    public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm";public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";/*** 创建Jackson对象映射器** @param builder Jackson对象映射器构建器* @return ObjectMapper*/@Primary@Bean("objectMapper")public ObjectMapper getJacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {ObjectMapper objectMapper = builder.createXmlMapper(false).build();//序列换成json时,将所有的long变成string.因为js中得数字类型不能包含所有的java long值,超过16位后会出现精度丢失SimpleModule simpleModule = new SimpleModule();// 字符传转为StringsimpleModule.addSerializer(Long.class, ToStringSerializer.instance);simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);// 时间格式化simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)));simpleModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)));simpleModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));// 反序列化simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT)));simpleModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)));simpleModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT)));objectMapper.registerModule(simpleModule);//反序列化的时候如果多了其他属性,不抛出异常objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);//日期格式处理objectMapper.setDateFormat(new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT));return objectMapper;}
}

2、统一响应格式化输出


/*** 系统拦截器及资源配置** @author helloWorld* <p>* 2018年10月20日*/
@EnableWebMvc
@Configuration
@RequiredArgsConstructor
public class WebMvcConfigurerAdapter implements WebMvcConfigurer {private final ObjectMapper objectMapper;/*** Jackson的全局序列化方式* <p>* long 转为 string* LocalData 格式化** @param converters*/@Overridepublic void extendMessageConverters(List<HttpMessageConverter<?>> converters) {MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();converter.setObjectMapper(objectMapper);converters.add(0, converter);converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));}
}

通过WebMvcConfigurer配置接口响应json数据的统一格式化。

http://www.dtcms.com/a/520611.html

相关文章:

  • 虚拟交易网站开发网站流量图怎么做
  • OpenTelemetry Agent直接到Jaeger链路跟踪
  • Monorepo系列:Pnpm Workspace 搭建 Monorepo
  • 有没有专门做字体排版设的网站实时热点新闻事件2021
  • 【开题答辩全过程】以 基于BS模式的图书馆管理系统为例,包含答辩的问题和答案
  • Java循环结构全解析:从基础用法到性能优化(含经典案例)
  • C 位域:核心地带,引领技术前沿
  • 鹤壁专业做网站公司前端培训心得
  • python-87-Pyinstaller打包在没有安装Python的电脑上运行
  • 海北高端网站建设多少钱网站后台登陆密码破解
  • CrewAI 核心概念(Knowledge)篇
  • 预检查和表单提交
  • [MySQL] 数据库设计
  • 数据处理像搭乐高?详解 RAGFlow Ingestion Pipeline
  • 模仿网站属于侵权吗做网站视频是什么专业
  • 汽车转向控制 / 线控转向介绍——控制技术——智能驾驶专栏
  • 基于KSP密钥管理系统的汽车 ECU JTAG 调试接口动态授权与安全管控
  • 世界经理人网站手机版学生网页网站制作软件大全
  • 企业网站带新闻发布功能的建站wordpress文章显示颜色
  • SpringBoot-Web开发之Web原生组件注入
  • Spring Cloud - Spring Cloud 本地配置(本地配置概述、本地配置实现)
  • 青岛商城网站建设长春建设平台网站的公司
  • 这几年做网站怎么样wordpress adsense主题
  • 做视频网站服务器怎么选择12306网站开发时间
  • 如何做家教网站赚钱如何申请国外网站
  • 淄博做网站建设云南网站建设方案
  • 实用指南--多账号矩阵防封控
  • 前端框架Vue(Vue 的挂载点与 data 数据对象)
  • pycharm 远程连接服务器添加github copilot
  • 金融智能体的技术底座解析:AI Agent如何实现“认知+执行”闭环?