【7.2.5】【date】更新日期格式

pull/37/head
fengshuonan 2022-09-24 21:51:00 +08:00
parent b4a37b42b3
commit afb128fdfe
2 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,92 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.wrapper.starter;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* Java8 string
*
* @author luopeng
* @date 2022/9/24 21:15
*/
@Configuration
public class GunsDateConvertAutoConfiguration {
/**
* LocalDateRequestParamPathVariable
*
* @author luopeng
* @date 2022/9/24 21:16
*/
@Bean
public Converter<String, LocalDate> localDateConverter() {
return source -> LocalDate.parse(source, DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN));
}
/**
* LocalDateTimeRequestParamPathVariable
*
* @author luopeng
* @date 2022/9/24 21:16
*/
@Bean
public Converter<String, LocalDateTime> localDateTimeConverter() {
return source -> LocalDateTime.parse(source, DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
}
/**
* LocalTimeRequestParamPathVariable
*
* @author luopeng
* @date 2022/9/24 21:18
*/
@Bean
public Converter<String, LocalTime> localTimeConverter() {
return source -> LocalTime.parse(source, DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN));
}
/**
* DateRequestParamPathVariable
*
* @author luopeng
* @date 2022/9/24 21:40
*/
@Bean
public Converter<String, Date> dateConverter() {
return source -> DateUtil.parse(source.trim());
}
}

View File

@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.wrapper.starter.GunsWrapperAutoConfiguration
cn.stylefeng.roses.kernel.wrapper.starter.GunsWrapperAutoConfiguration,\
cn.stylefeng.roses.kernel.wrapper.starter.GunsDateConvertAutoConfiguration