Spring MVC InternalPathMethodNameResolver tutorial with example


InternalPathMethodNameResolver

    Simple implementation of MethodNameResolver that maps URL to method name. Although this is the default implementation used by the MultiActionController class (because it requires no configuration), it's bit naive for most applications. 

In particular, we don't usually want to tie URL to implementation methods.

Maps the resource name after the last slash, ignoring an extension. 
E.g. "/foo/bar/baz.html" to "baz" 
Doesn't support wildcards.

Prefix + action + suffix = methodname (test + add + Customer)

Example
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-3.0.xsd  
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
    <!-- ************************************************************* --> 
    
 <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
  
<!-- ************************************************************* --> 

<bean class="com.candidjava.springmvc.CustomerController">
    
    <property name="methodNameResolver">
        
        <bean class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver">
            
            <property name="prefix" value="test" />
            <property name="suffix" value="Customer" />
            
        </bean>
        
    </property>
    
 </bean>

<!-- ************************************************************* --> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    
	<property name="prefix">		    
			<value>/WEB-INF/pages/</value>
	</property>	
		
		
	<property name="suffix">
	 	<value>.jsp</value>
	</property>    
	    
</bean>

	<!-- ************************************************************* -->
	

	<!-- ************************************************************* -->
	
</beans>

package com.candidjava.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;



public class CustomerController extends MultiActionController
{

	public ModelAndView testaddCustomer(HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		ModelAndView model = new ModelAndView("page");
		model.addObject("msg", "add() method");
		return model;
		

	}

	public ModelAndView testdeleteCustomer(HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		ModelAndView model = new ModelAndView("page");
		model.addObject("msg", "delete() method");
		return model;

		

	}

}


Screenshot
            
            
            

Download
        InternalPathMethodNameResolver maven zip
        InternalPathMethodNameResolver war


Related Post

Comments


©candidjava.com