I'm doing a course to make a task management tool using Udemy's React and Spring Boot, and I didn't understand the annotations at all, so I will summarize the annotations I used.
Controller.java
| Annotation | meaning |
|---|---|
| @RestController | Used when creating a class that is the entry point of WebAPI |
| @RequestMapping | Map paths and HTTP methods |
| @CrossOrigin | Allow access in CORS settings |
| @PostMappting | Annotations for POST requests |
| @GetMapping | Annotation for GET request |
| @DeleteMapping | Annotation for DELETE request |
| @PatchMapping | Annotations for PATCH requests |
Service.java
| Annotation | meaning |
|---|---|
| @Service | Managed by Spring Boot container when the app starts |
| @Autowired | Inject bean |
Repository.java
| Annotation | meaning |
|---|---|
| @Repository | Managed by Spring Boot container when the app starts |
| @Override | Be sure to override the method |
Exception.java
| Annotation | meaning |
|---|---|
| @ControllerAdvice | Special method dedicated to Controller(@Exception handler etc.)To@RestControllerTo付与したクラスで共有できる |
| @RestController | Recognized as Controller |
| @ExceptionHandler | You can make settings for exceptions that occur in the Controller class. |
| @ResponseStatus | Set HTTP status code |
Domain.java
| Annotation | meaning |
|---|---|
| @Entity | Defined to be a JPA entity |
| @Id | @Adapt Generated Value |
| @GeneratedValue | Generate primary key |
| @OneToOne | You can create a one-to-one relationship. Cascade can also be specified |
| @OneToMany | Have a one-to-many relationship. Cascade can also be specified |
| @ManytoOne | You can create a many-to-one relationship. Cascade can also be specified |
| @JoinColumn | Used when adding columns |
| @JsonIgnore | Excludes Json output |
| @NotBlank | Required. Null, empty string, space cannot be entered |
| @Size | You can limit the number of characters |
| @Column | Columns can be set |
| @JsonFormat | You can convert it to the format you want to output and output it. |
| @PrePersist | Specify the process to be executed before object persistence |
| @PreUpdate | Specifies what to do before the object's attributes are updated |
Recommended Posts