If your base url looks like this: http: // localhost / myapp / , where myapp is your context, then myapp / a.html, myapp / b.html myapp / c.html will be mapped to the first method 3 in the next controller. But everything else will reach the last method that matches **. Note that if you put the ** associated method at the top of your controller, then the whole request will reach that method.
Then this controller will fulfill your requirement:
@Controller
@RequestMapping("/")
public class ImportController{
@RequestMapping(value = "a.html", method = RequestMethod.GET)
public ModelAndView getA(HttpServletRequest req) {
ModelAndView mv;
mv = new ModelAndView("a");
return mv;
}
@RequestMapping(value = "b.html", method = RequestMethod.GET)
public ModelAndView getB(HttpServletRequest req) {
ModelAndView mv;
mv = new ModelAndView("b");
return mv;
}
@RequestMapping(value = "c.html", method = RequestMethod.GET)
public ModelAndView getC(HttpServletRequest req) {
ModelAndView mv;
mv = new ModelAndView("c");
return mv;
}
@RequestMapping(value="**",method = RequestMethod.GET)
public String getAnythingelse(){
return "redirect:/404.html";
}
source
share