Skip to content

Commit 10c7454

Browse files
committed
문자를 입력하면 IpPort 객체를 만들어 반환하는 컨버터
1 parent d578050 commit 10c7454

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package hello.typeconverter.converter;
2+
3+
import hello.typeconverter.type.IpPort;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.core.convert.converter.Converter;
6+
7+
@Slf4j
8+
public class StringToIpPortConverter implements Converter<String, IpPort> {
9+
10+
@Override
11+
public IpPort convert(String source) {
12+
log.info("convert source={}", source);
13+
// 127.0.0.1:8080 -> IpPort 객체
14+
String[] split = source.split(":");
15+
String ip = split[0];
16+
int port = Integer.parseInt(split[1]);
17+
return new IpPort(ip, port);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)