文章目录
Boolean.TRUE 和 true 性能对比
- A,D > B,C
// 7.844
Boolean A(){
return Boolean.TRUE;
}
// 10.109
boolean B(){
return Boolean.TRUE
}
// 7.906
Boolean C(){
return true;
}
// 7.828
boolean D(){
return true;
}
字符串为空isEmpty和isBlank的区别
- isEmpty仅仅是判断空和长度为0字符串
- isBlank判断的是空,长度为0,空白字符(包括空格,制表符\t,换行符\n,换页符\f,回车\r)组成的字符串
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("aaa") = false
StringUtils.isEmpty("\t \n \r \f") = false
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUitls.isBlank(" ") = true
StringUtils.isEmpty("aaa") = false
StringUtils.isEmpty("\t \n \r \f") = true
- hutool工具:StrUtil
System.out.println(StrUtil.isEmpty(null)); // true
System.out.println(StrUtil.isEmpty("")); // true
System.out.println(StrUtil.isEmpty(" ")); // false
System.out.println(StrUtil.isEmpty("aaa")); // false
System.out.println(StrUtil.isEmpty("\r \t \n \f")); // false
System.out.println(StrUtil.isBlank(null)); // true
System.out.println(StrUtil.isBlank("")); // true
System.out.println(StrUtil.isBlank(" ")); // true
System.out.println(StrUtil.isBlank("aaa")); // false
System.out.println(StrUtil.isBlank("\r \n \t \f")); // true
Swagger-ApiModel 和ApiModelProperty
- ApiModel 注解:该属性就是对所需要特别说明的接口相关实体类进行描述
属性名称 | 属性类型 | 默认值 | 作用 |
---|---|---|---|
value() | String | 空 | 自定义类的名称 |
description() | String | 空 | 为类添加长文本描述信息 |
- ApiModelProperty 注解:该属性就是对实体类中的参数进行一个描述
属性名称 | 属性类型 | 默认值 | 作用 |
---|---|---|---|
value() | String | 空 | 定义参数描述信息 |
name() | String | 空 | 定义参数名称 |
required() | boolean | false | 定义参数是否必传 |
hidden() | boolean | false | 定义参数是否隐藏 |
allowEmptyValue() | boolean | false | 定义参数是否允许为空 |
@ApiModel(value = "用户实体,存储用户相关字段", description = "用户实体中包含用户相关的所有业务字段,如有需要请另行添加")
public class User{
// do something...
}
@ApiModelProperty(value = "用户Id")
private Integer id;
Swagger-ApiOperation和ApiParam
- @ApiOperation 注解不是Spring 自带的,它是swagger里的com.wordnik.swagger.annotations.ApiOperation;
- 注解@ApiOperation 和@ApiParam是用来构建Api 文档的
- @ApiOperation(value=“接口说明”,httpMethod=“接口请求方式”,response=“接口返回参数类型”,notes=“接口发布说明”),用在请求的方法上,说明方法的用途、作用
- @ApiParam(required =“是否必须参数”,name=“参数名称”,value=“参数具体描述”)
其他注解:
- @ApiImplicitParams:用在请求的方法上,表示一组参数说明
- @Api:用在请求的类上,表示对类的说明
- @ApiImplicitParams:用在请求的方法上,表示一组参数说明
- @ApiResponses:用在请求的方法上,表示一组响应
- 参考链接
BeanUtils.copyProperties
-
浅拷贝,如果都是单一的属性,那么不涉及到深拷贝的问题,适合用BeanUtils
-
BeanUtils.copyProperties(a, b);
- b中的存在的属性,a中一定要有,但是a中可以有多余的属性;
- a中与b中相同的属性都会被替换,不管是否有值;
- a、 b中的属性要名字相同,才能被赋值,不然的话需要手动赋值;
- Spring的BeanUtils的CopyProperties方法需要对应的属性有getter和setter方法;
- 如果存在属性完全相同的内部类,但是不是同一个内部类,即分别属于各自的内部类,则spring会认为属性不同,不会copy;
- spring和apache的copy属性的方法源和目的参数的位置正好相反,所以导包和调用的时候都要注意一下