package cn.reghao.oss.console.config.spring;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDateTime;

/**
 * @author reghao
 * @date 2021-05-19 09:17:45
 */
@Configuration
public class MvcDataConverter {
    /**
     * 将前端提交的 "2021-05-19T11:09:14.034664"(即 LocalDateTime toString 的结果) 反序列化为 LocalDateTime 对象
     *
     * @param
     * @return
     * @date 2021-05-19 上午11:35
     */
    @Bean
    public Converter<String, LocalDateTime> localDateTimeDeserializer() {
        return new Converter<String, LocalDateTime>() {
            @Override
            public LocalDateTime convert(String source) {
                return LocalDateTime.parse(source);
            }
        };
    }
}
