티스토리 뷰
1. create some argument resolver class
import org.springframework.core.MethodParameter;
import org.springframework.mobile.device.Device;
import org.springframework.mobile.device.DeviceResolver;
import org.springframework.mobile.device.LiteDeviceResolver;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import javax.servlet.http.HttpServletRequest;
public class SomeArgumentResolver implements HandlerMethodArgumentResolver {
private final DeviceResolver deviceResolver = new LiteDeviceResolver();
@Override
public boolean supportsParameter(MethodParameter parameter) {
return Device.class.isAssignableFrom(parameter.getParameterType());
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
final Device device = deviceResolver.resolveDevice(webRequest.getNativeRequest(HttpServletRequest.class));
return device;
}
}
2. create some argument resolver bean
@Bean
public SomeAugumentResolver someAugumentResolver() {
return new SomeAugumentResolver();
}
3. regiest some argument resolver
public class SomeConfiguration extend WebMvcConfigurerAdapter {
...
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(someAugumentResolver());
}
}
argument resolver는 controller에서 사용할 객체나 데이터를 전처리 할 때 사용한다.
'Programming > Spring' 카테고리의 다른 글
AOP (0) | 2019.03.27 |
---|---|
Request Proxy (0) | 2019.03.27 |
Interceptor (1) | 2019.03.27 |
DI (Dependency Injection) (2) | 2018.11.01 |
Spring Application Start Flow (0) | 2018.10.06 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Spring Registrar
- Query DSL
- Join Table
- JPA
- Charles proxy
- Spring JDBC Template
- scikit-learn
- SmartLifecycle
- Property
- java EqualsAndHashCode
- Akka
- docker
- Mapping
- DI
- java Equals
- Typesafe Config
- java generic
- Sprint RetryTemplate
- Registrar
- spring spel
- RetryTemplate
- Spring
- Discriminate Mapping
- 복합키 Mapping
- guava
- Criteria
- JPA Criteria
- @Primary
- Embeddable Mapping
- Embedded Mapping
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함