mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
✨ Introducing new features. closed #1391 GET请求支持时间字符串到JAVA8对象的自动转换
This commit is contained in:
1 parent
c0dee9a37c
commit
b52030f56d
1 file changed
+29
-1
+29
-1
@@ -17,22 +17,50 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.data.resolver;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SpringMvc 规则增强
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2019-06-24
|
||||
* @date 2020-06-17
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 增加请求参数解析器,对请求中的参数注入SQL 检查
|
||||
* @param argumentResolvers
|
||||
*/
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
argumentResolvers.add(new SqlFilterArgumentResolver());
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加GET请求参数中时间类型转换 {@link com.pig4cloud.pigx.common.core.jackson.PigxJavaTimeModule}
|
||||
* <ul>
|
||||
* <li>HH:mm:ss -> LocalTime</li>
|
||||
* <li>yyyy-MM-dd -> LocalDate</li>
|
||||
* <li>yyyy-MM-dd HH:mm:ss -> LocalDateTime</li>
|
||||
* </ul>
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
|
||||
registrar.setTimeFormatter(DateTimeFormatter.ofPattern(DatePattern.NORM_TIME_PATTERN));
|
||||
registrar.setDateFormatter(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN));
|
||||
registrar.setDateTimeFormatter(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
|
||||
registrar.registerFormatters(registry);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user