@RequestParam使用defaultValue屬性設置默認值的操作
@RequestParam使用defaultValue屬性設置默認值
註意設置必須是string類型的,框架自己會做轉換
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false) Integer size,
補充:@RequestParam註解的使用說明
自SpringMVC4.2之後,RequestParam內部有4個參數:
1、String name;
2、String value;
3、boolean required;
4、String defaultValue;
源碼中name的別名是value,value的別名是name,
所以說name和value兩個屬性基本是等價的,都是獲取從前臺傳入的參數
RequestParam來映射請求參數
required表示是否必須,默認為true
defaultValue請求參數的默認值
@RequestMapping(value = "/testRequestParam") public String testRequestParam(@RequestParam(value="username")String un,@RequestParam(value = "age",required = false,defaultValue = "0") int age){ System.out.println("testRequestParam,username:"+un+",age,"+age); return "success"; }
<script> (function(){ function setArticleH(btnReadmore,posi){ var winH = $(window).height(); var articleBox = $("div.article_content"); var artH = articleBox.height(); if(artH > winH*posi){ articleBox.css({ 'height':winH*posi+'px', 'overflow':'hidden' }) btnReadmore.click(function(){ if(typeof window.localStorage === "object" && typeof window.csdn.anonymousUserLimit === "object"){ if(!window.csdn.anonymousUserLimit.judgment()){ window.csdn.anonymousUserLimit.Jumplogin(); return false; }else if(!currentUserName){ window.csdn.anonymousUserLimit.updata(); } } articleBox.removeAttr("style"); $(this).parent().remove(); }) }else{ btnReadmore.parent().remove(); } } var btnReadmore = $("#btn-readmore"); if(btnReadmore.length>0){ if(currentUserName){ setArticleH(btnReadmore,3); }else{ setArticleH(btnReadmore,1.2); } } })() </script> </article>
以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。如有錯誤或未考慮完全的地方,望不吝賜教。
推薦閱讀:
- 淺談@RequestParam 參數是否必須傳的問題
- 聊聊@RequestParam,@PathParam,@PathVariable等註解的區別
- @RequestParam 接收參數的值為null的處理方式
- 解決使用@RequestParam註解和泛型遇到的問題
- 關於@RequestParam註解的使用(簡單易懂)