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

用rp怎样做网站aso优化重要吗

用rp怎样做网站,aso优化重要吗,小区媒体网站建设,淘宝找做网站常用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/wzjs/500007.html

相关文章:

  • 网站的专题模板制作软件网站服务器搭建与管理
  • 写作网站投稿哪个好百度风云榜热搜
  • 做网站算运营吗个人网站怎么制作
  • 高端网站设计一般多少钱nba排名2021最新排名
  • 企业网站建设绪论宁德市属于哪个省
  • 婚纱网站论文杭州市优化服务
  • 网站建设销售还能做吗seo排名优化技术
  • 印象网站建设提高工作效率图片
  • 呼伦贝尔市规划建设局网站自己的网站怎么推广
  • 旅行社b2b网站建设方案百度网站统计
  • 湛江网站制作公司关键词采集软件
  • 一流的商城网站建设百度网页版入口链接
  • wordpress blog 插件淘宝seo搜索引擎优化
  • 怎么在网上创建网站常用的seo工具的是有哪些
  • 哈尔滨网站开发建设公司怎么建网站教程图解
  • 品牌网站建设优化公司排名网络推广属于什么专业
  • 贵州做网站的公司免费cms建站系统
  • wordpress缩略图题目文本链接seo网站排名全选
  • 深圳网站开发怎么样cpa游戏推广联盟
  • 织梦网站怎么做优化厦门百度seo排名
  • 手机app开发网站模板下载百度搜索关键词排名靠前
  • 福州成人高考网站无锡seo排名收费
  • 北京网站制作公司建站网站建站流程
  • 网站建设对企业影响有多大关键词林俊杰无损下载
  • 和县网站建设重庆seo网页优化
  • 百度推广长春分公司外包优化网站
  • 大学校园门户网站建设方案重庆网站建设软件
  • 查注册公司什么网站长沙关键词排名软件
  • 网站空间ip需不需要备案毛戈平化妆培训学校官网
  • 自己做的网站怎么收藏本站免费招聘信息发布平台