Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package web.mvc.controllers; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; /** * * @author CodeFire */ @Controller @RequestMapping("/messages") public class HelloController { @RequestMapping("/hello") public ModelAndView showHelloPage(@RequestParam(value = "user", required = false) String name) { ModelAndView mav = new ModelAndView("hello-page"); mav.addObject("message", name == null ? "Hello guest!" : "Hello " + name + '!'); return mav; } @RequestMapping("/goodbye") public ModelAndView showGoodbyePage(String name) { ModelAndView mav = new ModelAndView("hello-page"); mav.addObject("message", "Goodbye user! " + name + '!'); return mav; } @RequestMapping("/page/{user}") public ModelAndView showMessagePage(@PathVariable("user") String name) { ModelAndView mav = new ModelAndView("hello-page"); mav.addObject("message", name == null ? "Hello guest!" : "Hello " + name + '!'); return mav; } }