일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- spring
- Exception
- JPQL
- AOP
- 백준
- 스프링 핵심 기능
- springdatajpa
- 자바
- 김영한
- 스프링 핵심 원리
- JDBC
- Greedy
- 인프런
- 스프링
- db
- kotlin
- transaction
- SpringBoot
- jpa
- 알고리즘
- Thymeleaf
- Servlet
- QueryDSL
- Proxy
- http
- pointcut
- 그리디
- java
- Spring Boot
- Android
- Today
- Total
목록ConversionService (4)
개발자되기 프로젝트
스프링은 자바에서 기본으로 제공하는 타입들에 대해 수 많은 포맷터를 기본으로 제공 Formatter 인터페이스의 구현 클래스에는 수 많은 날짜나 시간 관련 포맷터가 제공됨. 그런데 포맷터는 기본 형식이 지정되어 있기 때문에, 객체의 각 필드마다 다른 형식으로 포맷을 지정하기는 어려움. 1. Spring 제공 Formatter @Annotaion 기반으로 원하는 형식을 지정 @NumberFormat : 숫자 관련 형식 지정 포맷터 사용, NumberFormatAnnotationFormatterFactory @DateTimeFormat : 날짜 관련 형식 지정 포맷터 사용, Jsr310DateTimeFormatAnnotationFormatterFactory 2. Controller @Controller pu..
Thymeleaf에 Converter를 적용해보자. 1. Controller @Controller public class ConverterController { @GetMapping("/converter-view") public String converterView(Model model){ model.addAttribute("number", 10000); model.addAttribute("ipPort", new IpPort("127.0.0.1", 8080)); return "converter-view"; } } 2. converter-view.html ${number}: ${{number}}: ${ipPort}: ${{ipPort}}: 기존과는 다르게 ${{...}}가 있다. ${number}: ${{..
1. Spring에 Converter 등록 addFormatters() 이용 @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { registry.addConverter(new StringToIntegerConverter()); registry.addConverter(new StringToIpPortConverter()); registry.addConverter(new IntegerToStringConverter()); registry.addConverter(new IpPortToStringConverter()); } }..
1. ConversionService 개별 컨버터를 모아두고 그것들을 묶어서 편리하게 사용할 수 있는 기능 package org.springframework.core.convert; import org.springframework.lang.Nullable; public interface ConversionService { boolean canConvert(@Nullable Class sourceType, Class targetType); boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType); T convert(@Nullable Object source, Class targetType); Object conver..