type converter : regist converter(spring)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package hello.typeconverter;
|
||||
|
||||
import hello.typeconverter.converter.IntegerToStringConverter;
|
||||
import hello.typeconverter.converter.IpPortToStringConverter;
|
||||
import hello.typeconverter.converter.StringToIntegerConverter;
|
||||
import hello.typeconverter.converter.StringToIpPortConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
registry.addConverter(new StringToIntegerConverter());
|
||||
registry.addConverter(new IntegerToStringConverter());
|
||||
registry.addConverter(new StringToIpPortConverter());
|
||||
registry.addConverter(new IpPortToStringConverter());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package hello.typeconverter.controller;
|
||||
|
||||
import hello.typeconverter.type.IpPort;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -23,4 +24,10 @@ public class HelloController {
|
||||
System.out.println("data = " + data);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@GetMapping("/ip-port")
|
||||
public String ipPort(@RequestParam IpPort ipPort) {
|
||||
System.out.println("ipPort = " + ipPort);
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package hello.typeconverter.type;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class IpPort {
|
||||
private String ip;
|
||||
private int port;
|
||||
|
||||
Reference in New Issue
Block a user