PathController.java
package com.monkey1024.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/*
*获取url中的数据
*PathVariable
*/
@Controller
public class PathController01 {
@RequestMapping("/{username}/{age}/path.do")
public ModelAndView getPath(@PathVariable("username") String name,@PathVariable int age) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("username", name);
mv.addObject("age", age);
mv.setViewName("result");
return mv;
}
}
result.jsp
Insert title here
姓名:${username }
年龄:${age }