spring boot 自定义配置文件的类型转换
来源:互联网 发布:朝鲜脱北者 知乎 编辑:程序博客网 时间:2024/05/29 04:21
配置文件
application.yml
myYml: date: 20101020
String To Date 转换
public class StringToDateConverter implements Converter<String, Date> { public Date convert(String source) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); try { return sdf.parse(source); } catch (ParseException e) { e.printStackTrace(); return null; } }}
int To Date 转换
public class IntegerToDateConverter implements Converter<Integer, Date> { public Date convert(Integer source) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); try { return sdf.parse(String.valueOf(source)); } catch (ParseException e) { e.printStackTrace(); return null; } }}
注入类型转换bean
@Beanpublic ConversionService conversionService() { ConversionServiceFactoryBean bean = new ConversionServiceFactoryBean(); Set<Converter> converters = new HashSet<>(); converters.add(new StringToDateConverter()); converters.add(new IntegerToDateConverter()); bean.setConverters(converters); bean.afterPropertiesSet(); return bean.getObject();}
阅读全文
0 0
- spring boot 自定义配置文件的类型转换
- spring-boot 如何加载rsources下面的自定义配置文件
- spring boot 自定义logback日志配置文件
- Spring boot之读取自定义配置文件
- Spring-boot中读取核心配置文件application和自定义properties配置文件的方式
- spring-boot(0) application.properties配置文件和自定义配置文件
- spring boot 注册类型转换 (转载)
- Spring Boot系列(二):Spring Boot的配置文件
- 自定义类型转换器解决Spring配置文件注入类型错误的问题 PropertyEditorSupport
- Spring的类型转换
- spring boot 添加自定义配置文件并读取属性
- Spring boot 通过@ConfigurationProperties和@PropertySource读取自定义配置文件信息
- spring boot 配置文件后缀的一个坑
- Spring Boot配置文件乱码的问题
- spring自定义配置文件的加载
- Spring MVC JSON自定义类型转换
- Spring MVC JSON自定义类型转换
- Spring MVC JSON自定义类型转换
- 416. Partition Equal Subset Sum
- Leetcode7. Reverse Integer
- 浅析Java中HashMap的底层原理
- Netty的群发实现2
- 第一次CCF CSP认证体验
- spring boot 自定义配置文件的类型转换
- Unity Android 加载动态库
- 大数据WEB阶段 (十)Response、ServletConfig、ServletContext、资源跳转三种方式
- jQuery学习笔记(四)封装js框架
- Excel和CSV格式文件的不同之处
- IETF/RFC--TCP/IP/Ethernet--IP分片
- C6748_NMI
- Eclipse4.5.0安装Spring插件springsource-tool-suite
- eclipse没有自动编译出.class文件