通过在控制器方法中使用@RequestParam(value="参数名",require=true/false,defaultvalue="")的方式,使在URL中传入参数。

 

控制器代码:

SpringMVC(九) RequestMapping请求参数_spring
package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class RequestParamTest {
    @RequestMapping("testRequestParam")
    public String testRequestParam(@RequestParam(value="id",required=false,defaultvalue="10") Integer id){
        System.out.println(id);
        return "success";
    }
}
SpringMVC(九) RequestMapping请求参数_spring

 

视图代码:

 <a href="testRequestParam?id=3">TestRequestParam</a>
[ 尐鱼儿的QQ群:726994578 ] --- [ https://github.com/godmaybelieve ]