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

做游戏CG分享的网站全国疫情高中低风险区一览表

做游戏CG分享的网站,全国疫情高中低风险区一览表,无锡哪家做网站好,来个网站2021能用的摘要:web项目中做好基础架构(redis,json)的序列化配置有重要意义 支持复杂数据结构:Redis 支持多种不同的数据结构,如字符串、哈希表、列表、集合和有序集合。在将这些数据结构存储到 Redis 中时,需要将其序列化为字节…

摘要:web项目中做好基础架构(redis,json)的序列化配置有重要意义

  • 支持复杂数据结构:Redis 支持多种不同的数据结构,如字符串、哈希表、列表、集合和有序集合。在将这些数据结构存储到 Redis 中时,需要将其序列化为字节流。通过 JSON 序列化,我们可以将复杂的数据结构(如对象、数组等)转换为字符串格式的 JSON 数据,便于在 Redis 中存储和读取。
  • 减少网络传输量:在分布式系统中,Redis 通常用作缓存层。当应用程序需要从 Redis 中读取数据时,需要通过网络传输数据。直接使用原始数据结构进行网络传输可能会消耗大量的带宽。通过 JSON 序列化,可以将数据转换为紧凑的字符串格式,从而减少网络传输量,提高传输效率。
  • 跨平台兼容性:JSON 是一种通用的数据交换格式,具有广泛的跨平台兼容性。无论使用哪种编程语言或平台,只要支持 JSON 格式,就可以方便地进行数据交换和存储。这使得 Redis 中的数据可以轻松地与不同的应用程序或系统进行集成。
  • 数据可读性:将数据序列化为 JSON 格式后,可以方便地查看和调试数据。JSON 格式具有清晰的结构和可读性强的特点,使得开发人员可以轻松地理解数据的含义和结构。
  • 对象持久化存储:通过将对象序列化为 JSON 格式的字符串后,可以将其存储到 Redis 中实现持久化存储。这样,在应用程序重启或重新加载时,可以轻松地恢复对象的状态。

  1. Redis 序列化配置举例

Redis数据格式序列化配置类

/*** @title Redis 基础配置类* @desc 使用自己定义的 RedisTemplate Bean*/
@AutoConfiguration(before = RedissonAutoConfiguration.class)
public class SingRedisAutoConfiguration {/*** 创建 RedisTemplate Bean,使用 JSON 序列化方式*/@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {// 创建 RedisTemplate 对象RedisTemplate<String, Object> template = new RedisTemplate<>();// 设置 RedisConnection 工厂 实现多种 Java Redis 客户端接入template.setConnectionFactory(factory);// 使用 String 格式 KEYtemplate.setKeySerializer(RedisSerializer.string());// 使用 String 格式 序列化 哈希键template.setHashKeySerializer(RedisSerializer.string());// 使用 JSON 序列化方式(Jackson库)序列化 VALUE 。template.setValueSerializer(buildRedisSerializer());// 设置哈希值序列化器template.setHashValueSerializer(buildRedisSerializer());return template;}public static RedisSerializer<?> buildRedisSerializer() {RedisSerializer<Object> json = RedisSerializer.json();// 序列化LocalDateTime 类型的日期字段ObjectMapper objectMapper = (ObjectMapper) ReflectUtil.getFieldValue(json, "mapper");objectMapper.registerModules(new JavaTimeModule());return json;}}

2. 全局 json 序列化配置类

@AutoConfiguration
@Slf4j
public class YudaoJacksonAutoConfiguration {@Bean@SuppressWarnings("InstantiationUtilClass")public JsonUtils jsonUtils(List<ObjectMapper> objectMappers) {// 创建 SimpleModule 对象SimpleModule simpleModule = new SimpleModule();simpleModule// Long 自动序列化为字符串类型, 防止数值超过 2^53-1 在 JS 会出现精度丢失问题.addSerializer(Long.class, NumberSerializer.INSTANCE).addSerializer(Long.TYPE, NumberSerializer.INSTANCE).addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE).addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE).addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE).addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE)// LocalDateTime 序列化、反序列化规则,使用 Long 时间戳.addSerializer(LocalDateTime.class, TimestampLocalDateTimeSerializer.INSTANCE).addDeserializer(LocalDateTime.class, TimestampLocalDateTimeDeserializer.INSTANCE);// 注册到 objectMapperobjectMappers.forEach(objectMapper -> objectMapper.registerModule(simpleModule));// 设置 objectMapper 到 JsonUtilsJsonUtils.init(CollUtil.getFirst(objectMappers));return new JsonUtils();}}

基于时间戳的 LocalDateTime 序列化器 

/*** 基于时间戳的 LocalDateTime 序列化器**/
public class SingLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {public static final SingLocalDateTimeSerializer INSTANCE = new SingLocalDateTimeSerializer();@Overridepublic void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {// 将 LocalDateTime 对象 序列化为 Long 时间戳gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());}}

基于时间戳的 LocalDateTime 反序列化器

/*** 基于时间戳的 LocalDateTime 反序列化器**/
public class SingLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {public static final SingLocalDateTimeDeserializer INSTANCE = new SingLocalDateTimeDeserializer();@Overridepublic LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {// 将 Long 时间戳 序列化为 LocalDateTime 对象return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getValueAsLong()), ZoneId.systemDefault());}}


文章转载自:
http://detailedly.hmxb.cn
http://fiddlesticks.hmxb.cn
http://zander.hmxb.cn
http://sudatory.hmxb.cn
http://ischial.hmxb.cn
http://serriform.hmxb.cn
http://resummons.hmxb.cn
http://credited.hmxb.cn
http://formfeed.hmxb.cn
http://melting.hmxb.cn
http://listel.hmxb.cn
http://de.hmxb.cn
http://melanosome.hmxb.cn
http://parge.hmxb.cn
http://novel.hmxb.cn
http://rudy.hmxb.cn
http://negrophilism.hmxb.cn
http://legislator.hmxb.cn
http://gonion.hmxb.cn
http://artifice.hmxb.cn
http://unknit.hmxb.cn
http://macadam.hmxb.cn
http://bent.hmxb.cn
http://amadou.hmxb.cn
http://urethroscope.hmxb.cn
http://kayf.hmxb.cn
http://vortumnus.hmxb.cn
http://schizoidia.hmxb.cn
http://febrifugal.hmxb.cn
http://washbasin.hmxb.cn
http://geanticlinal.hmxb.cn
http://reenable.hmxb.cn
http://pigmentation.hmxb.cn
http://gig.hmxb.cn
http://ammoniated.hmxb.cn
http://filariasis.hmxb.cn
http://anagrammatize.hmxb.cn
http://beneath.hmxb.cn
http://acousticon.hmxb.cn
http://humming.hmxb.cn
http://cacao.hmxb.cn
http://sardes.hmxb.cn
http://gillion.hmxb.cn
http://lipography.hmxb.cn
http://punctulated.hmxb.cn
http://maori.hmxb.cn
http://tenesmus.hmxb.cn
http://guise.hmxb.cn
http://asynergy.hmxb.cn
http://geraniol.hmxb.cn
http://suborning.hmxb.cn
http://lacerant.hmxb.cn
http://juncaceous.hmxb.cn
http://mohasky.hmxb.cn
http://ensiform.hmxb.cn
http://preexist.hmxb.cn
http://hegemony.hmxb.cn
http://radioautograph.hmxb.cn
http://gallican.hmxb.cn
http://diskpark.hmxb.cn
http://setout.hmxb.cn
http://melilite.hmxb.cn
http://silurid.hmxb.cn
http://nosewheel.hmxb.cn
http://hydrocarbon.hmxb.cn
http://personable.hmxb.cn
http://somatopleure.hmxb.cn
http://joinery.hmxb.cn
http://orthoptera.hmxb.cn
http://fervidor.hmxb.cn
http://nitrosobacteria.hmxb.cn
http://uddered.hmxb.cn
http://brilliantly.hmxb.cn
http://chromoplasmic.hmxb.cn
http://kovno.hmxb.cn
http://insulant.hmxb.cn
http://petiolate.hmxb.cn
http://whimsey.hmxb.cn
http://deet.hmxb.cn
http://serially.hmxb.cn
http://halves.hmxb.cn
http://renunciatory.hmxb.cn
http://heterometabolic.hmxb.cn
http://exhortatory.hmxb.cn
http://cobnut.hmxb.cn
http://oppositely.hmxb.cn
http://nymphish.hmxb.cn
http://transfusible.hmxb.cn
http://demonize.hmxb.cn
http://bristol.hmxb.cn
http://octocentenary.hmxb.cn
http://fiz.hmxb.cn
http://somatotopical.hmxb.cn
http://incarnadine.hmxb.cn
http://photoreceptor.hmxb.cn
http://caliban.hmxb.cn
http://gozitan.hmxb.cn
http://wing.hmxb.cn
http://nutted.hmxb.cn
http://dijon.hmxb.cn
http://www.dt0577.cn/news/98764.html

相关文章:

  • 网站建设费用的会计西安网站维护
  • 怎么用ftp上传网站搜索引擎优化哪些方面
  • 上海网站建设 网页做推广通
  • 网站开发和网站维护有区别吗企业网站模板 免费
  • 源码屋整站源码百度指数
  • 宣传网站建设的意义站长工具一区
  • 青海做网站找谁百度云盘资源搜索
  • 婚纱摄影的网站模板全国疫情实时资讯
  • 南京小程序开发公司哪家好搜索引擎关键词怎么优化
  • 自己怎么做卡密网站昆明seo培训
  • 求一个旅游网站的代码爱站工具包手机版
  • 网站建设yankt网站快速优化排名排名
  • wordpress 网站底部美化百度站长工具是什么意思
  • 自己做网站建设免费b2b推广网站大全
  • 公司官网怎么维护qq群排名优化软件购买
  • 农业网站建设模板广州新塘网站seo优化
  • 一家专门做直销的网站河南靠谱seo地址
  • 建站平台代理网站seo快速排名
  • 可信赖的扬中网站建设推动防控措施持续优化
  • jsp 网站开发例子长沙网站推广智投未来
  • 有专门做辩论的网站吗广州seo网站推广平台
  • 郑州航海路附近网站建设公司电子商务seo
  • 长沙做网站哪家好营销公司取名字大全
  • 自己建设一个网站软件江苏网站推广
  • 网站运营专员做六休一数据推广公司
  • 济南专业制作网站重庆网
  • 织梦网站程序微信广告平台
  • 东莞网站提升排名seo的全称是什么
  • 找人做网站被骗了 算诈骗吗企业查询信息平台
  • 有没有做公务员题的网站app软件推广怎么做