当前位置 : 主页 > 编程语言 > java >

@RequestParam使用defaultValue属性设置默认值的操作

来源:互联网 收集:自由互联 发布时间:2021-04-03
@RequestParam使用defaultValue属性设置默认值 注意设置必须是string类型的,框架自己会做转换 @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,@RequestParam(value = "size", required = f

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持易盾网络。如有错误或未考虑完全的地方,望不吝赐教。

网友评论