Conversation
sah3122
left a comment
There was a problem hiding this comment.
마지막 미션 구현 잘해주셨습니다 😄
이번 미션에서 경험하는것이 좋을것 같아 추가 과제 남겨두었는데 확인 부탁드려요 !
| return (type.isPrimitive() && type != void.class) || | ||
| type == Double.class || type == Float.class || type == Long.class || | ||
| type == Integer.class || type == Short.class || type == Character.class || | ||
| type == Byte.class || type == Boolean.class || type == String.class; |
There was a problem hiding this comment.
Primitive Type을 관리할수 있는 클래스를 추출해보는건 어떨까요 ?
| return (ModelAndView) method.invoke(object, request, response); | ||
| } | ||
|
|
||
| private boolean isParameterMappingMethod() { |
There was a problem hiding this comment.
지원하는 파라미터에 대해 HandlerExcution에서 관리하도록 정의해주셨는데 HandlerMethodArgumentResolver의 구현을 경험해보는것이 어떨가 싶어 의견 남겨 놓습니다 😄
파라미터 순서와 수에 따라 매핑을 하지 않고 Application에서 지원하는 파라미터 타입을 관리해보도록 정의해보세요 😄
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java
| private static Object convertValue(Class<?> clazz, String value) { | ||
| if( Boolean.class == clazz || Boolean.TYPE == clazz) return Boolean.parseBoolean( value ); | ||
| if( Byte.class == clazz || Byte.TYPE == clazz) return Byte.parseByte( value ); | ||
| if( Short.class == clazz || Short.TYPE == clazz) return Short.parseShort( value ); | ||
| if( Integer.class == clazz || Integer.TYPE == clazz) return Integer.parseInt( value ); | ||
| if( Long.class == clazz || Long.TYPE == clazz) return Long.parseLong( value ); | ||
| if( Float.class == clazz || Float.TYPE == clazz) return Float.parseFloat( value ); | ||
| if( Double.class == clazz || Double.TYPE == clazz) return Double.parseDouble( value ); | ||
| return value; |
There was a problem hiding this comment.
36-41 라인의 기능과 함꼐 별도의 클래스로 관리 해볼수 있을것 같습니다 😄
|
|
||
| public ModelAndView handle(final HttpServletRequest request, final HttpServletResponse response) throws Exception { | ||
| if (isParameterMappingMethod()) { | ||
| return (ModelAndView) method.invoke(object, convertToMethodArg(method, request.getRequestURI(), request.getParameterMap())); |
There was a problem hiding this comment.
HandlerMethodArgumentResolver를 구현하여 request, response 객체 또한 메서드 파라미터로 함꼐 전달할수 있도록 변경해보세요 😄
아래의 기능을 추가하였습니다