使用@RequestParam綁定請求參數到方法參數


@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")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM