본문 바로가기
Programming/Spring

ParameterMethodNameResolver

by 막이 2014. 7. 16.

ParameterMethodNameResolver는 parameter에 설정된 method를 request 를 처리할 method 를 결정한다.

ex> action.do?method=update 요청이 들어오면 method(HttpServletRequest , HttpServletResponse) 메소드를 호출한다.

With ParameterMethodNameResolver configured, and define the parameter name thought the “paramName” property:

<beans ...>
 
 <bean 
  class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
 
  <bean class="com.mkyong.common.controller.CustomerController">
     <property name="methodNameResolver">
	<bean class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
	   <property name="paramName" value="action"/>
	</bean>
     </property>
   </bean>
 
</beans>

Now, the URL will map to the method name via the “action” request parameter name :

  1. /customer/*.htm?action=add –> add() method
  2. /customer/whatever.htm?action=add –> add() method
  3. /customer/*.htm?action=update –> update() method
  4. /customer/*.htm?action=delete –> delete() method
  5. /customer/*.htm?action=list –> list() method