使用@RequestMapping注解
可以在类/方法上加
@Controller
@RequestMapping("url")//http://localhost:8080/url/u01.do 类级别
public class UrlController {
@RequestMapping("u01")//方法级别
public ModelAndView fun(){
ModelAndView mv=new ModelAndView();
mv.addObject("fun","function");
mv.setViewName("hello");
return mv;
}
@RequestMapping(value = {"/u03","u04"},method = {RequestMethod.GET })//方法级别
public ModelAndView fun1(){
ModelAndView mv=new ModelAndView();
mv.addObject("fun","function1");
mv.setViewName("hello");
return mv;
}
@RequestMapping(params = "u05")//访问时必须有参数才能访问
public ModelAndView fun2(){
ModelAndView mv=new ModelAndView();
mv.addObject("fun","function2");
mv.setViewName("hello");
return mv;
}
}
标签:addObject,RequestMapping,URL,地址,mv,fun,ModelAndView,public
From: https://www.cnblogs.com/lwx11111/p/16769785.html