spring3学习笔记(1)-----RequestMapping与页面路径
@RequestMapping的参数如下
/**
* @see RequestMapping 参数
* @param value
* 需要跳转的地址
* @param mehtod
* 基于RestFul的跳转参数,有RequestMethod.get post,put 等
* @param params
* 符合某个参数的时候才调用该方法
* @param headers
* 符合头信息的时候才调用
* */
?
<bean id="viewResolver"value="org.springframework.web.servlet.view.JstlView" /><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp"></property></bean>?
@Controller@RequestMapping("/test")public class HelloWorldController {static Logger logger = Logger.getLogger(HelloWorldController.class.getName());@RequestMapping("/hello")public void Hello() {logger.info("The hello() method is use");}?根据以上配置,方法无返回值时,默认寻找以下路径:spring3.X/WEB-INF/jsp/test/hello.jsp
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+prefix
?
?
修改代码返回ModelAndView对象:
@RequestMapping("/hello")public ModelAndView Hello() {ModelAndView modelAndView = new ModelAndView();modelAndView.setViewName("hello");return modelAndView;}路径:spring3.X/WEB-INF/jsp/hello.jsp(prefix+viewName+suffix)。
?
返回Map对象:
?
@SuppressWarnings("unchecked")@RequestMapping("/hello")public Map Hello() {Map map = new HashMap();map.put("map","hello");return map;}?路径:spring3.X/WEB-INF/jsp/test/hello.jsp,和第一种方法无返回值的情况类似:
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+suffix
?
返回一个ModelMap类型,使用modelMap.addAllAttributes将map中的所有元素添加到modelMap中,并显示到页面上。
@SuppressWarnings("unchecked")@RequestMapping("/hello")public ModelMap Hello() {ModelMap modelMap = new ModelMap();HashMap hashMap = new HashMap();hashMap.put("h", "hello");modelMap.addAttribute("w", "world");/** Copy all attributes in the supplied Collection into this Map, using attribute name generation for each element.**/modelMap.addAllAttributes(hashMap);return modelMap;}?路径:spring3.X/WEB-INF/jsp/test/hello.jsp
prefix+类路径(类级别的mapping注解)+方法路径(方法级别的mapping注解)+suffix
<body>页面路径:hello/hello.jsp<br />${h},${w}</body>?
?
?
?
?
?
?