【用法样例:】
package com.lyh.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HelloController {
@RequestMapping("/get/{id}")
public String show(@PathVariable("id") Integer id){
return "hello";
}
}
【举例:】
【index.jsp】
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<html>
<head>
<title>首页</title>
</head>
<body>
<form action="/testRequestParam/1">
<label for="nickname">姓名</label>
<input type="text" id="nickname" name ="nickname" placeholder="请输入姓名..." />
<label for="password">密码</label>
<input type="password" id="password" name ="password" placeholder="请输入密码..." />
<label for="age">年龄</label>
<input type="text" id="age" name ="age" placeholder="请输入年龄..." />
<label for="salary">工资</label>
<input type="text" id="salary" name ="salary" placeholder="请输入工资..." />
<input type="submit" value="test requestParam"/>
</form>
</body>
</html>
【hello.jsp】
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<html>
<head>
<title>Test RequestParam</title>
</head>
<body>
<h2>${message}</h2>
<h2>${msg}</h2>
</body>
</html>
【HelloController.java】
package com.lyh.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping(value = "/testRequestParam/{id}")
public ModelAndView testRequestParam(@PathVariable("id") Integer id, @RequestParam(value = "nickname") String nickname,
@R