当前位置:网站首页>项目中的基础知识
项目中的基础知识
2022-07-19 06:39:00 【早上真起不来!】
文章目录
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属性的方法源和目的参数的位置正好相反,所以导包和调用的时候都要注意一下
边栏推荐
- Codeforces Round #808 (Div. 2)(A,B,C)
- 关于风机滑环的寿命以及工作原理
- 软件开发设计流程
- Does MySQL have ROWID like virtual columns?
- 类型详解(枚举+联合)
- redisson分布式锁续期因为网络原因失败了,导致业务还在执行但锁没续期而自动释放了。
- Dynamically adjust impala log level
- [yunyuansheng boy rushes into the Ninth Heaven of IVX platform] 1: project creation of actual ivx-0 code programming experience
- 知识增强的NLP预训练模型【将知识图谱中的三元组向量引入到预训练模型中】
- 利用SQL注入漏洞实习读写文件
猜你喜欢
使用 PyCharm 设置虚拟环境
MGRE环境下的OSPF实验
Introduction to impala metadata
Application of split slip ring in motor
Codeforces Round #807 (Div. 2)(A.B.C)
快解析结合微信小程序开发
Oracle trigger SQL error
優化yum源之優化base庫
Cake cutting problem [Olympiad Mathematics in grade two of primary school]
Conversion code from "implementation details" character index to word index
随机推荐
Assimp库中文文档
H5 introduction of Web debugging tools and vconsole
Towhee 每日模型周报
Will it be optimized if you add a condition to sort by half insertion?
JS operation properties, styles and events
wx:小程序传值
快解析如何与私有化部署结合
软件开发设计流程
Does MySQL have ROWID like virtual columns?
低频量化之可转债埋伏配债、埋伏埋伏配债和配债选股策略
Setting up a virtual environment using pycharm
Uncover the lie and truth of empty block attack
C4 learning materials (to be continued)
The nearest common ancestor of binary tree
类型详解(枚举+联合)
884 · 寻找排列
優化yum源之優化base庫
Pikachu shooting range SQL injection digital injection (post) clearance steps
redisson分布式锁续期因为网络原因失败了,导致业务还在执行但锁没续期而自动释放了。
(illustration) the context of FPN