Swagger2 common notes, Java Junior Engineer Interview Questions

@GetMapping("/page")

@ApiOperation(value = "Paging query user list")

@ApiImplicitParams({

        @ApiImplicitParam(name = "pageNum", value = "Current number of pages"),

        @ApiImplicitParam(name = "pageSize", value = "Records per page")

})

public List<UserDTO> page(

        @RequestParam(defaultValue = "1", required = false) Integer pageNum, @RequestParam(defaultValue = "10", required = false) Integer pageSize) {

    return list;

}



@GetMapping("/{userId}")

@ApiOperation(value = "According to user id Query user")

public UserDTO get(@PathVariable("userId") Integer userId) {

    for (UserDTO userDTO : list) {

        if (userDTO.getUserId().equals(userId)) {

            return userDTO;

        }

    }

    return new UserDTO();

}



@PostMapping

@ApiOperation(value = "New user")

public Boolean insert(@RequestBody @ApiParam(name = "UserDTO", value = "Add user parameters") UserDTO userDTO) {

    list.add(userDTO);

    return true;

}



@DeleteMapping("/{userId}")

@ApiOperation(value = "According to user id delete user")

public Boolean delete(@PathVariable("userId") Integer userId) {

    Iterator<UserDTO> iterator = list.iterator();

    while (iterator.hasNext()) {

        if (iterator.next().getUserId().equals(userId)) {

            iterator.remove();

            return true;

        }

    }

    return false;

}



@PutMapping

@ApiOperation(value = "Update user information")

@ApiResponses({

        @ApiResponse(code = 400, message = "Request parameters are not filled in"),

        @ApiResponse(code = 404, message = "The requested path does not exist or the page Jump path is incorrect")

})

public Boolean update(@RequestBody @ApiParam(name = "UserDTO", value = "Update user parameters") UserDTO userDTO) {

    Iterator<UserDTO> iterator = list.iterator();

    while (iterator.hasNext()) {

        UserDTO next = iterator.next();

        if (next.getUserId().equals(userDTO.getUserId())) {

            next.setUsername(userDTO.getUsername());

            return true;

        }

    }

    return false;

}

}



this controller There are six interfaces, namely:



1.  /user/list,get Request method: query user list

2.  /user/page,get Request method: paging query user list

3.  /user/{userId},get Request method: according to the user id Query user

4.  /user,post Request method: Add User

5.  /user,put Request method: update user information

6.  /user/{userId},delete Request method: according to the user id delete user



### [] () provider document



Start the project and access it in the browser [http://localhost:8080/doc.html]( )



Homepage display API Basic information of the document, including introduction, author, version, etc



![Insert picture description here](https://img-blog.csdnimg.cn/20200602174346583.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoaW5rV29u,size_16,color_FFFFFF,t_70#pic_center)



Users can be seen at the same time controller All interfaces



![Insert picture description here](https://img-blog.csdnimg.cn/20200602174415936.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoaW5rV29u,size_16,color_FFFFFF,t_70#pic_center)



Here we debug the following interface to query the user list



![Insert picture description here](https://img-blog.csdnimg.cn/20200602174437969.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RoaW5rV29u,size_16,color_FFFFFF,t_70#pic_center)



So far, Spring Boot integrate Swagger2,structure API The document is complete



[]( )Swagger2 Common notes

--------------------------------------------------------------------------



### [] () notes related to Controller



#### []( )@Api



Used on the requested class to represent the description of the class



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **tags** | String\[\] | Describes the role of the request class. If it is not empty, it will be overwritten value Value of |

| **value** | String | Describes the role of the request class |

| Unusual parameters |  |  |

| produces | String | set up MIME Type list( output),Example:“ application/json, application/xml",The default is empty |

| consumes | String | set up MIME Type list( input),Example:“ application/json, application/xml",The default is empty |

| protocols | String | Set specific protocols, for example: http, https, ws, wss |

| authorizations | Authorization\[\] | Gets the authorization list (Security statement). If it is not set, an empty authorization value is returned |

| hidden | boolean | Default to false,Configure as true Hide in document |

| description | String | yes api Resource description, in 1.5 No longer supported after version |

| basePath | String | The basic path can not be configured. It can be set at 1.5 No longer supported after version |

| position | int | If more than one is configured Api To change the order and position of the display, click 1.5 No longer supported after version |



Example



@Api(tags = {"user controller"})

public class UserController {}



### [] () interface related notes



#### []( )@ApiOperation



It is used on the method of the request class to explain the purpose and function of the method



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **value** | String | Brief description of the method |

| **notes** | String | Remarks on the method |

| Unusual parameters |  |  |

| tags | String\[\] | Operation label. It will be overwritten if it is not empty value Value of |

| response | Class<?> | Response type (i.e. return object) |

| responseContainer | String | Declares a wrapped response container (return object type). Valid values are“ List", "Set" or "Map" |

| responseReference | String | Specifies a reference to the response type. Any specified will be overwritten response()class |

| httpMethod | String | appoint HTTP Method“ GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS" and "PATCH" |

| position | int | If more than one is configured Api To change the order and position of the display, click 1.5 No longer supported after version |

| nickname | String | Unique identifier of the third-party tool. It is blank by default |

| responseHeaders | ResponseHeader\[\] | Response header list |

| code | int | Responsive HTTP Status code. Default is 200 |

| extensions | Extension\[\] | Extended attribute list array |

| produces | String | set up MIME Type list( output),Example:“ application/json, application/xml",The default is empty |

| consumes | String | set up MIME Type list( input),Example:“ application/json, application/xml",The default is empty |

| protocols | String | Set specific protocols, for example: http, https, ws, wss |

| authorizations | Authorization\[\] | Gets the authorization list (Security statement). If it is not set, an empty authorization value is returned |

| hidden | boolean | Default to false,Configure as true Hide in document |



Example



@GetMapping("/list")

@ApiOperation(value = "query user list")

public List list() {

return list;

}



#### []( )@ApiParam



It can be used in methods, parameters and fields. It is generally used in request body parameters to describe request body information



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **name** | String | Parameter name. The parameter name can override the method parameter name. The path parameter must be consistent with the method parameter |

| **value** | String | Brief description of parameters |

| **required** | boolean | Parameter must be passed. The default value is false (Path parameter (required) |

| **defaultValue** | String | Default values for parameters |

| Unusual parameters |  |  |

| allowableValues | String | Limit the acceptable value of the parameter. 1.Comma separated list 2.Range value 3.Set minimum value/Maximum |

| access | String | Allow from API Filter parameters in document |

| allowMultiple | boolean | Specifies whether the parameter can accept multiple values by having multiple events. The default is false |

| example | String | Single example |

| examples | Example | Parameter example. Applies only to BodyParameters |

| hidden | boolean | Default to false,Configure as true Hide in document |



@PostMapping

@ApiOperation(value = "new user")

public Boolean insert(@RequestBody @ApiParam(name = "UserDTO", value = "new user parameter") (UserDTO){

list.add(userDTO);

return true;

}



#### []( )@ApiImplicitParams



It is used in the requested method to represent a set of parameter descriptions, which are`@ApiImplicitParam`list



#### []( )@ApiImplicitParam



Used in `@ApiImplicitParams` Annotation, a description of a request parameter



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **name** | String | Parameter name. The parameter name can override the method parameter name. The path parameter must be consistent with the method parameter |

| **value** | String | Description and interpretation of parameters |

| **required** | boolean | Parameter must be passed. The default value is false (Path parameter (required) |

| **paramType** | String | The location of the parameter, header Acquisition of request parameters:`@RequestHeader`;query Acquisition of request parameters:`@RequestParam`;path(be used for restful Interface)–> Acquisition of request parameters:`@PathVariable`;body(Not commonly used); form((not commonly used) |

| **dataType** | String | Parameter type, default String,Other values dataType="Integer" |

| **defaultValue** | String | Default values for parameters |

| Unusual parameters |  |  |

| allowableValues | String | Limit the acceptable value of the parameter. 1.Comma separated list 2.Range value 3.Set minimum value/Maximum |

| access | String | Allow from API Filter parameters in document |

| allowMultiple | boolean | Specifies whether the parameter can accept multiple values by having multiple events. The default is false |

| example | String | Single example |

| examples | Example | Parameter example. Applies only to BodyParameters |



@GetMapping("/page")

@ApiOperation(value = "paging query problem list")

@ApiImplicitParams({

@ApiImplicitParam(name = "pageNum", value = "Current number of pages"),

@ApiImplicitParam(name = "pageSize", value = "Records per page")

})

public List page(

@RequestParam(defaultValue = "1", required = false) Integer pageNum, @RequestParam(defaultValue = "10", required = false) Integer pageSize) {

return list;

}



#### []( )@ApiResponses



Used on a request method to represent a set of responses



#### []( )@ApiResponse



Used in `@ApiResponses` It is generally used to express the response information of an error



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **code** | int | Response status code |

| **message** | String | Information, such as "request parameters are not filled in" |

| **response** | Class<?> | The class that threw the exception |



Example



@PutMapping

@ApiOperation(value = "update user information")

@ApiResponses({

@ApiResponse(code = 400, message = "Request parameters are not filled in"),

@ApiResponse(code = 404, message = "The requested path does not exist or the page Jump path is incorrect")

})

public Boolean update(@RequestBody @ApiParam(name = "UserDTO", value = "update user parameter") UserDTO userDTO) {}



### [] () Model related notes



#### []( )@ApiModel



It is used on the entity class (model) to represent the description of related entities.



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **value** | String | Alternate name for the model |

| **description** | String | Detailed description of this class |



Example



@ApiModel(value = "user", description = "query user")

public class UserDTO implements Serializable



#### []( )@ApiModelProperty



Used on an entity class attribute to represent the relevant description of the attribute.



| **Annotation Properties ** | **type** | **describe** |

| :-- | :-- | :-- |

| **value** | String | Property brief description |

| **name** | String | Override property name |

| **dataType** | Stirng | Override property type |

| **required** | boolean | Parameter is required. The default value is false |

| **example** | Stirng | Attribute example |

| Unusual parameters |  |  |

| hidden | boolean | Whether to hide this attribute in the document. The default value is false |

| allowEmptyValue | boolean | Allow to be blank, default false |

| allowableValues | String | Limit the acceptable value of the parameter. 1.Comma separated list 2.Range value 3.Set minimum value/Maximum |

| readOnly | boolean | Set the property to read-only, default false |

| reference | String | Specifies a reference to the corresponding type definition, overriding any specified parameter values |



Example



@ApiModelProperty(value = "user id")

private Integer userId;

last

CodeChina open source project: [analysis of Java interview questions of front-line large manufacturers + core summary learning notes + latest explanation Video]

ActiveMQ message middleware interview topic

  • What is ActiveMQ?
  • What if the ActiveMQ server goes down?
  • What about losing the message?
  • What if persistent messages are very slow?
  • What about the uneven consumption of news?
  • What about the dead letter queue?
  • Is the message retransmission interval and number of times in ActiveMQ?

Analysis and expansion of ActiveMQ message middleware interview topic:

redis interview topics and answers

  • What are the clients that support consistent hashing?
  • How is Redis different from other key value stores?
  • What is the memory usage of Redis?
  • What are the ways to reduce Redis's memory usage?
  • What commands are used to view Redis usage and status information?
  • What happens when Redis runs out of memory?
  • Redis is single threaded. How to improve the utilization of multi-core CPU?

Spring interview topics and answers

  • Talk about your understanding of Spring
  • What are the advantages of Spring?
  • Design patterns in Spring
  • How to open annotation assembly and common annotations
  • Briefly introduce the life cycle of spring beans

Analysis and expansion of Spring interview answers

Highly concurrent multithreaded interview topics

  • There are now threads T1, T2, and T3. How do you ensure that T2 threads execute after T1 and T3 threads execute after T2?
  • What are the advantages of the new Lock interface in Java over synchronized block s? If you implement a high-performance cache that supports concurrent reads and single writes, how do you ensure data integrity.
  • What is the difference between wait and sleep methods in Java?
  • How to implement a blocking queue in Java?
  • How to write code in Java to solve producer consumer problems?
  • Write a deadlock code. How do you solve deadlock in Java?

Analysis and expansion of highly concurrent multithreaded interview

jvm interview topics and analysis

  • What are the components of a JVM?
  • JVM memory partitioning?
  • Java's memory model?
  • Classification of references?
  • When does GC start?

JVM interview topic analysis and expansion!

  • How to open annotation assembly and common annotations
  • Briefly introduce the life cycle of spring beans

Analysis and expansion of Spring interview answers

[external chain picture transferring... (IMG wiubk3ln-1631076450535)]

Highly concurrent multithreaded interview topics

  • There are now threads T1, T2, and T3. How do you ensure that T2 threads execute after T1 and T3 threads execute after T2?
  • What are the advantages of the new Lock interface in Java over synchronized block s? If you implement a high-performance cache that supports concurrent reads and single writes, how do you ensure data integrity.
  • What is the difference between wait and sleep methods in Java?
  • How to implement a blocking queue in Java?
  • How to write code in Java to solve producer consumer problems?
  • Write a deadlock code. How do you solve deadlock in Java?

Analysis and expansion of highly concurrent multithreaded interview

[external chain picture transferring... (img-fP1TSUgk-1631076450536)]

jvm interview topics and analysis

  • What are the components of a JVM?
  • JVM memory partitioning?
  • Java's memory model?
  • Classification of references?
  • When does GC start?

JVM interview topic analysis and expansion!

[external chain picture transferring... (img-UMLhqPTg-1631076450538)]

Tags: Java Back-end Programmer RESTful http

Posted on Wed, 24 Nov 2021 05:45:10 -0500 by Box