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
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
姓名:${username }
<br>
年龄:${age }
</body>
</html>