目录

前端向后端传LocalDateTime需要在后端写的日期格式转换配置

目录

前端向后端传LocalDateTime需要在后端写的日期格式转换配置

本菜鸡新学会的小玩意

前端向后端传LocalDateTime会报格式错误的异常。此时需要我们在后端配置日期格式

Converter引用的包为:

import org.springframework.core.convert.converter.Converter;
    @Bean
    Converter<String,LocalDateTime> dateTimeConverter(){
        return new Converter<String, LocalDateTime>() {
            @Override
            public LocalDateTime convert(String s) {
                return LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            }
        };