SpringMVC(九) RequestMapping请求参数
通过在控制器方法中使用@RequestParam(value="参数名",require=true/false,defaultvalue="")的方式,使在URL中传入参数。
控制器代码:
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"; } }
视图代码:
<a href="testRequestParam?id=3">TestRequestParam</a>
https://github.com/godmaybelieve