Spring Boot 最常用注解

686 阅读1分钟

组件与配置

@Component

@RestController

@Service

@Repository

@Configuration


RestController中使用

Restful Api路由

@RequestMapping

@PostMapping

@GetMapping

@DeleteMapping

@PutMapping

@PatchMapping


@PathVariable

@RequestParam

@RequestBody


Lombok

@Getter/@Setter

@Builder

@NoArgsConstructor

@RequiredArgsConstructor

@AllArgsConstructor

@Data

@Value(staticConstructor="of")

@ToString


JSON

@JsonIgnoreProperties(ignoreUnknown = true)

@JsonInclude(value = JsonInclude.Include.NON_NULL)


JPA

@Entity

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

@Column

@CreatedDate

@LastModifiedDate


Log

@Slf4j


Swagger

@Api()

@ApiOperation()


测试

@Test

@Mock


数据验证

@Valid

@Email

@Range

@Min

@Max

@NotNull

@Size