首页 > 其他分享 >通用解决LocalDateTime转为字符串后中间含“T”

通用解决LocalDateTime转为字符串后中间含“T”

时间:2023-08-17 14:34:16浏览次数:35  
标签:jackson class Bean LocalDateTime 字符串 import 转为 public

import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 通用解决LocalDateTime转为字符串后中间含“T”
 */
@Configuration
public class LocalDateTimeSerializerConfig {

    @Bean
    public LocalDateTimeSerializer localDateTimeSerializer() {
        return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    @Bean
    public LocalDateTimeDeserializer localDateTimeDeserializer() {
        return new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }


    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            builder.serializerByType(LocalDateTime.class, localDateTimeSerializer());
//            builder.deserializerByType(LocalDateTime.class, localDateTimeDeserializer());
        };
    }

}

标签:jackson,class,Bean,LocalDateTime,字符串,import,转为,public
From: https://www.cnblogs.com/shareToAll/p/17637476.html

相关文章

  • 某公司笔试题 - 删除字符串中出现次数最少的字符(附python代码)
    #实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输入删除这些单词后的字符串,字符串中其它字符保持原来的顺序。#数据范围:输入的字符串长度满足1<=n<=20,保证输入的字符串中仅出现小写字母str1=input().lower()dic={}if1<......
  • 《字符串篇》_T("字符串")的作用
    参考链接:https://www.jianshu.com/p/83622b5a9f62问题:经常我们会在程序中看到字符串直接被这样使用_T("完成"),好端端的字符串为什么用_T()处理呢?解答:字符串“完成”前加了个_T,这是因为本工程创建的时候用的默认的Unicode字符集,而如果“完成”前不加_T就是ASCII字符串_T实际上是......
  • java判断字符串是否包含某个字符(串)
    判断一个字符串是否包含某个子串的n种方法startsWith()contains方法indexOf方法startsWith()这个方法有两个变体并测试如果一个字符串开头的指定索引指定的前缀或在默认情况下从字符串开始位置此方法定义的语法如下:publicbooleanstartsWith(Stringprefix,inttoffset)orpubl......
  • 差值数组不同的字符串
    给你一个字符串数组words,每一个字符串长度都相同,令所有字符串的长度都为n。每个字符串words[i]可以被转化为一个长度为n-1的差值整数数组difference[i],其中对于0<=j<=n-2有difference[i][j]=words[i][j+1]-words[i][j]。注意两个字母的差值定义为它们......
  • 带密匙的字符串加密解密函数(支持中文)
    usesAnsiStrings; FunctionJiaMi(Src:String;Key:String):String; var  KeyLen:Integer;  KeyPos:Integer;  offset:Integer;  dest:String;  SrcPos:Integer;  SrcAsc:Integer;  Range:Integer;  IntTemp:integer; ......
  • day08-字符串part01
    344. 反转字符串详解classSolution{public:voidreverseString(vector<char>&s){intleft=0;intright=s.size()-1;while(left<=right){//chartmp=s[left];//s[left]=s[right];......
  • php 字符串进行加*处理
    /$string是字符串$start从第几个开始加*$end从结尾第几个开始*publicfunctionstrReplace($string,$start,$end){$strlen=mb_strlen($string,'UTF-8');//获取字符串长度$firstStr=mb_substr($string,0,$start,'UTF-8');//获取第一位$l......
  • python中自定义类对象json字符串化的方法
    1.用json或者simplejson就可以2.定义转换函数:defconvert_to_builtin_type(obj):print'default(',repr(obj),')'#把MyObj对象转换成dict类型的对象d={}d.update(obj.__dict__)returnd 3.定义类classObject():name=""size=0def__init__(......
  • 判断文件是否是XML格式以及判断字符串是否是XML格式
    首先截取文件后缀名。后缀是XML文件再进入此判断,避免不必要的资源占用。/***判断一个文件是否是XML文件**@paramfile*@return*/privatestaticbooleanisXmlDocument(Filefile){booleanflag;try{DocumentBuilderFactoryfactory=Docume......
  • python编程从入门到实践(第2版)学习笔记(变量,字符串)
    变量变量是一种可以赋给值的标签。每一个变量都指向一个相关联的值,下列代码中message即为变量,指向的值为“HelloPythonworld!”message="HelloPythonworld!"print(message)第二行的print()函数用于打印输出这个message变量所关联的值。且变量的值是可以修改的,p......