Spring MVC Annotation Multi Action tutorial with example



We can have more than one operation in Single controller class, also spring allow us to write lot of flexible methods to handle request 

Code

package com.candidjava.springmvc;

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

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@RequestMapping(value = "/customer")
@Controller
public class CustomerController
{

	@RequestMapping(value = "/add.htm", method = RequestMethod.GET)
	public ModelAndView add() throws Exception
	{

		ModelAndView mv = new ModelAndView("page");
		mv.addObject("msg", "add() method");

		return mv;
	}

	@RequestMapping("/delete.htm")
	public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception
	{

		return new ModelAndView("page", "msg", "delete() method");

	}

	@RequestMapping("/update.htm")
	public String update() throws Exception
	{

		return "page1";

	}

	@RequestMapping("/*.htm")
	public String list() throws Exception
	{

		return "page2";

	}

}


Screenshot

            

                    


Download

            Spring MVC Multi Action maven zip

            Spring MVC Multi Action war



Related Post

Comments


©candidjava.com