码迷,mamicode.com
首页 > 其他好文 > 详细

使用@RequestParam绑定请求参数到方法参数

时间:2015-05-08 10:50:49      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

@RequestParam注解用于在控制器中绑定请求参数到方法参数.
用法如下:
@RequestMapping
 public void advancedSearch(
   @RequestParam("queryStr") String queryStr,
   @RequestParam("showFlag") String showFlag,
   @RequestParam("totalnumber") String totalNumber,
   @RequestParam("upType") String upType,
   @RequestParam("jmesareq") String jmesaReq,
   @RequestParam("isExportOper") String isExportOper,
   HttpServletResponse response, final HttpServletRequest request,
   ModelMap model) {
  // get query structure and query type from page
  List<Long> cd_ids = new ArrayList<Long>();
  if(StringUtils.equals("invoke", jmesaReq)){
   cd_ids = (List<Long>)request.getSession().getAttribute(Constants.RESULT_IDS);
  }
 ....
 }

使用这个注解参数默认是必需的, 但是可以把@RequestParam的required属性设置为false从而让这个参数可选.
例如@RequestParam(value="name", required="false")

使用@RequestParam绑定请求参数到方法参数

标签:

原文地址:http://www.cnblogs.com/toSeeMyDream/p/4487015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!