Skip to content

Step4 파라미터 매핑 기능 추가#62

Open
newvelop wants to merge 16 commits intonext-step:newvelopfrom
newvelop:step4
Open

Step4 파라미터 매핑 기능 추가#62
newvelop wants to merge 16 commits intonext-step:newvelopfrom
newvelop:step4

Conversation

@newvelop
Copy link
Copy Markdown

아래의 기능을 추가하였습니다

  • 경로변수를 추출해서 파라미터로 전달 후 실행
  • 쿼리 파라미터를 변환해서 메서드 실행

Copy link
Copy Markdown

@sah3122 sah3122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마지막 미션 구현 잘해주셨습니다 😄
이번 미션에서 경험하는것이 좋을것 같아 추가 과제 남겨두었는데 확인 부탁드려요 !

Comment on lines +37 to +40
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primitive Type을 관리할수 있는 클래스를 추출해보는건 어떨까요 ?

return (ModelAndView) method.invoke(object, request, response);
}

private boolean isParameterMappingMethod() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지원하는 파라미터에 대해 HandlerExcution에서 관리하도록 정의해주셨는데 HandlerMethodArgumentResolver의 구현을 경험해보는것이 어떨가 싶어 의견 남겨 놓습니다 😄

파라미터 순서와 수에 따라 매핑을 하지 않고 Application에서 지원하는 파라미터 타입을 관리해보도록 정의해보세요 😄
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolver.java

Comment on lines +153 to +161
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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HandlerMethodArgumentResolver를 구현하여 request, response 객체 또한 메서드 파라미터로 함꼐 전달할수 있도록 변경해보세요 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants