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

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

时间:2023-10-07 10:35:23浏览次数:33  
标签:jackson LocalDateTimeSerializer LocalDateTime springframework org 字符串 import 转为

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.beans.factory.annotation.Value;
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转json的格式
 *
 * @since 2023-10-07
 */
@Configuration
public class LocalDateTimeSerializerConfig {
 
    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
    private String pattern;
 
    @Bean
    public LocalDateTimeSerializer localDateTimeDeserializer() {
        return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern));
    }
 
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
    }
}

 

标签:jackson,LocalDateTimeSerializer,LocalDateTime,springframework,org,字符串,import,转为
From: https://www.cnblogs.com/sandyyeh/p/17745732.html

相关文章

  • 前端歌谣的刷题之路-第三十八题-大写字符串
     目录前言题目 核心代码总结前言我是歌谣我有个兄弟巅峰的时候排名c站总榜19叫前端小歌谣曾经我花了三年的时间创作了他现在我要用五年的时间超越他今天又是接近兄弟的一天人生难免坎坷大不了从头再来歌谣的意志是永恒的放弃很容易但是坚持一定很酷本题目源自于牛客网......
  • C++将角度转为复数
    1.角度转复数,使用std::polar#include<iostream>#include<complex>#include<cmath>intmain(){floattheta=45;floattheta_pi=theta*(M_PI/180);std::cout<<"is"<<std::polar(1.0f,theta_pi)<<......
  • 字符串排序
    方法1:直接用数组排序publicclassStringSort{publicstaticvoidmain(String[]args){String[]strings={"abc123","abc+1234","ababab--1"};//对每个字符串计算字母字符个数和数字字符个数,并按照字母数字比和字符串本身大小排序Arra......
  • 如何检查一个字符串是否包含子字符串的JavaScript方法?
    内容来自DOChttps://q.houxu6.top/?s=如何检查一个字符串是否包含子字符串的JavaScript方法?通常,我会期望有一个String.contains()方法,但似乎没有这个功能。有什么合理的方式来检查这个吗?ECMAScript6引入了String.prototype.includes:conststring="foo";constsubstri......
  • 每个字符串从'/'到最后的内容都被替换为''
    list_1=['产品类型','后续机台','重量','可生产温度/℃','预计自然冷却时间/h','预计单面风机风机强冷时间/h','预计双面风机风机强冷时间/h']#请使用正则表达式给出pattern使得每个字符串从'/'到最后的内容都被替换为'',最终结果为['产品类型......
  • 基础算法--字符串
    \(KMP\)\(KMP\)算法(Knuth-Morris-Pratt算法)是一个著名的字符串匹配算法,效率很高,但是确实有点复杂。基本概念\(1\)、s[]是模式串,即比较长的字符串。\(2\)、p[]是模板串,即比较短的字符串。(这样可能不严谨。。。)\(3\)、“非平凡前缀”:指除了最后一个字符以外,一个字符串的全......
  • 【字符串】【哈希】ABC284F ABCBAC 题解
    ABC284F这题的正解是\(Z\)函数。如果\(str=T+T\)的话,若可以找到连续的分别长为\(n\)的两段,且这两段可通过\(1\)次翻转变为相同的字符串,那么便一定有解,否则无解。暴力判断是\(\mathcal{O}(n)\)的,时间复杂度直接上天。可以用哈希\(\mathcal{O}(1)\)地判断出两个......
  • 将np.datetime64的时间差转为秒
    print((np.datetime64('2023-01-0200:00:00')-np.datetime64('2023-01-0100:00:00'))/np.timedelta64(1,'s'),(pd.Series(np.datetime64('2023-01-0200:00:00'))-pd.Series(np.datetime64('2023-01-0100:0......
  • C# 中的字符串内插
    vardate=newDateTime(1731,11,25);Console.WriteLine($"On{date:dddd,MMMMdd,yyyy}LeonhardEulerintroducedtheletteretodenote{Math.E:F5}inalettertoChristianGoldbach.");//Expectedoutput://OnSunday,November25,1731Leonh......
  • Delphi dll 传递字符串
    //dllcodeuses//ShareMem,SysUtils,Windows,Math;{$R*.res}functionTestString1(Buffer:PChar):PChar;stdcall;varTmpstr:string;begintryTmpstr:=Buffer;ifTmpstr<>''thenbeginResult:=StrAlloc(Length......