Java学习-读代码D1

Controller

ApplicationController

Annotation

  1. **@RestController
//source code
@org.springframework.web.bind.annotation.RestController
@Controller
@ResponseBody
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Documented

A convenience annotation that is itself annotated with @Controller and @ResponseBody. Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default.

  1. @RequestMapping
@org.springframework.web.bind.annotation.RequestMapping
@Mapping
@Target(value={METHOD, TYPE})
@Retention(value=RUNTIME)
@Documented

Annotation for mapping web requests onto methods in request-handling classes with flexible method signatures. Both Spring MVC and Spring WebFlux support this annotation through a RequestMappingHandlerMapping and RequestMappingHandlerAdapter in their respective modules and package structure.

  1. @Api
@io.swagger.annotations.Api
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Inherited

Marks a class as a Swagger resource. By default, Swagger-Core will only include and introspect only classes that are annotated with @Api and will ignore other resources (JAX-RS endpoints, Servlets and so on).

  1. @Autowired
@org.springframework.beans.factory.annotation.Autowired
@Target(value={ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, PARAMETER})
@Retention(value=RUNTIME)
@Documented

Marks a constructor, field, setter method, or config method as to be autowired by Spring’s dependency injection facilities. This is an alternative to the JSR-330 javax.inject.Inject annotation, adding required-vs-optional semantics.

  1. @PostMapping @PutMapping @GetMapping @DeleteMapping
@org.springframework.web.bind.annotation.PostMapping
//get查询 put修改 post增 delete删除
@RequestMapping(method={POST})//method={Put} or {Get} or {Delete}
@Target(value={METHOD})
@Retention(value=RUNTIME)
@Documented

Annotation for mapping HTTP POST/Get/Put/Delete requests onto specific handler methods. Specifically, @PostMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.POST).

  1. @ApiOperation
@io.swagger.annotations.ApiOperation
@Target(value={METHOD, TYPE})
@Retention(value=RUNTIME)

Describes an operation or typically a HTTP method against a specific path. Operations with equivalent paths are grouped in a single Operation Object. A combination of a HTTP method and a path creates a unique operation.

  1. @PathVariable
@org.springframework.web.bind.annotation.PathVariable
@Target(value={PARAMETER})
@Retention(value=RUNTIME)
@Documented

Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for RequestMapping annotated handler methods. If the method parameter is Map<String, String> then the map is populated with all path variable names and values.

  1. @RequestBody
@org.springframework.web.bind.annotation.RequestBody
@Target(value={PARAMETER})
@Retention(value=RUNTIME)
@Documented

Annotation indicating a method parameter should be bound to the body of the web request. The body of the request is passed through an HttpMessageConverter to resolve the method argument depending on the content type of the request. Optionally, automatic validation can be applied by annotating the argument with @Valid. Supported for annotated handler methods.
9.@Data

@lombok.Data
@Data
@ApiModel(value="应用程序添加实体类")

Generates getters for all fields, a useful toString method, and hashCode and equals implementations that check all non-transient fields. Will also generate setters for all non-final fields, as well as a constructor. Equivalent to @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode.
9. ApiModel

@io.swagger.annotations.ApiModel
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Inherited

Provides additional information about Swagger models. Classes will be introspected automatically as they are used as types in operations, but you may want to manipulate the structure of the models.
10. ** ApiModelProperty**

@io.swagger.annotations.ApiModelProperty
@Target(value={FIELD, METHOD})
@Retention(value=RUNTIME)
//Adds and manipulates data of a model property.

11.ColumnType

@tk.mybatis.mapper.annotation.ColumnType
@Target(value={FIELD, METHOD})
@Retention(value=RUNTIME)
//针对列的复杂属性配置

返回类型

  1. ResponseEntity
//org.springframework.http.ResponseEntity<BaseResponse<Object>>
//Extension of HttpEntity that adds a HttpStatus status code. Used in RestTemplate as well @Controller methods. 
// In RestTemplate, this class is returned by  getForEntity() and  exchange():   
ResponseEntity<String> entity = template.getForEntity("https://example.com", String.class);
 String body = entity.getBody();
 MediaType contentType = entity.getHeaders().getContentType();
 HttpStatus statusCode = entity.getStatusCode();
 return ResponseEntity.status(HttpStatus.CREATED)
                .body(AdminResponse.result(GlobalConstant.SUCCESS, "保存成功!"));

CleanCacheController

这一部分主要用了redis的内容,功能是清除缓存

Annotation

1.@Slf4j

@lombok.extern.slf4j.Slf4j
@Slf4j
@RestController
@RequestMapping(value={"/api/rest/v1/caches-clean"})
//Causes lombok to generate a logger field.

CompanyController

增、删、改、查功能的实现

Annotation

1.JsonIgnoreProperties

@com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JacksonAnnotation
@Target(value={ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, TYPE})
@Retention(value=RUNTIME)

Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
2.@NotNull

@javax.validation.constraints.NotNull
@Repeatable(value=List.class)
@Constraint(validatedBy={})
@Target(value={TYPE_USE, ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, PARAMETER})
@Retention(value=RUNTIME)
@Documented

The annotated element must not be null. Accepts any type.
3. @JsonInclude

@com.fasterxml.jackson.annotation.JsonInclude
@JacksonAnnotation
@Target(value={ANNOTATION_TYPE, FIELD, METHOD, PARAMETER, TYPE})
@Retention(value=RUNTIME)

Annotation used to indicate when value of the annotated property (when used for a field, method or constructor parameter), or all properties of the annotated class, is to be serialized. Without annotation property values are always included, but by using this annotation one can specify simple exclusion rules to reduce amount of properties to write out.
4.JsonIgnoreProperties

@com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JacksonAnnotation
@Target(value={ANNOTATION_TYPE, CONSTRUCTOR, FIELD, METHOD, TYPE})
@Retention(value=RUNTIME)

Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).