Basic knowledge in the project

Boolean. Performance comparison between true and 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;
}

The difference between isEmpty and isBlank when the string is empty

  • isEmpty is just to judge empty and 0-length strings
  • isBlank judges a string composed of empty, 0-length, blank characters (including spaces, tabs, \t, newline \n, page feed \f, carriage return \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 tool: 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 and ApiModelProperty

  • ApiModel annotation: this attribute describes the interface related entity classes that need special description
Attribute nameAttribute typeDefault valueeffect
value()StringemptyName of custom class
description()StringemptyAdd long text description information to the class
  • ApiModelProperty annotation: this property is a description of the parameters in the entity class
Attribute nameAttribute typeDefault valueeffect
value()StringemptyDefine parameter description information
name()StringemptyDefine parameter name
required()booleanfalseDefine whether parameters are required
hidden()booleanfalseDefine whether the parameter is hidden
allowEmptyValue()booleanfalseDefine whether the parameter can be null
@ApiModel(value = "User entity, storing user related fields", description = "The user entity contains all business fields related to the user. Please add them separately if necessary")
public class User{
    // do something...
}
@ApiModelProperty(value = "user Id")
private Integer id;

Swagger apioperation and ApiParam

  • @Apioperation annotation is not Spring's own, it's COM in swagger wordnik. swagger. annotations. ApiOperation;
  • Annotations @ApiOperation and @ApiParam are used to build Api documents
  • @ApiOperation(value= "interface description", httpMethod= "interface request method", response= "interface return parameter type", notes= "interface release description") is used to describe the purpose and function of the requested method
  • @ApiParam(required = "parameter required", name= "parameter name", value= "parameter specific description")

Other notes:

  • @ApiImplicitParams: used on the requested method to represent a set of parameter descriptions
  • @Api: used on the requested class to indicate the description of the class
  • @ApiImplicitParams: used on the requested method to represent a set of parameter descriptions
  • @ApiResponses: used in the request method to represent a group of responses
  • Reference links

BeanUtils.copyProperties

  • Shallow copy, if it is a single attribute, does not involve the problem of deep copy. It is suitable to use BeanUtils

  • BeanUtils.copyProperties(a, b);

    • The existing attributes in b must exist in a, but there can be redundant attributes in a;
    • The same attributes in a and b will be replaced, regardless of whether there is a value;
    • a. The attribute in b must have the same name before it can be assigned, otherwise it needs to be assigned manually;
    • The CopyProperties method of Spring's BeanUtils requires corresponding properties such as getter and setter methods;
    • If there are internal classes with exactly the same attributes, but not the same internal class, that is, they belong to their own internal classes, spring will think that the attributes are different and will not copy;
    • The location of the method source and destination parameters of the copy attribute of spring and apache are exactly the opposite, so you should pay attention to it when importing packages and calling

Tags: Java Back-end Spring Boot

Posted by Ricklord on Fri, 15 Jul 2022 04:56:00 +0930