Annotations Flashcards
@Autowired
@Component
@Component
@ID
Use for Spring Data?
Generates the id automatically (PK in db???)
@Id–> from jakarta? JPA?
@Id –> form Springdata–> for reactive progaming?
JPA vs R2DBC?
@CreatedDate
@LastModifiedDate
–> from SpringData
–> they neeD the @EnableR2dbcAuditing annotation on the db @Configuration classs
Test annotation
@DataR2dbctest –> test slice
@Import(YourClass.class)
-> is this used in the test classes when using onlt test slicing OR???
@RestCOntroller
to implement the enpoints in the cotrollers package
@service
@mapper
Used with mapstruct maven plugin, mapstruct depedency
annotation an interface that has methods to transform from EntityToDto and from DtoToEntity
Difference between @Bean and @Autowired
@Bean tells Spring ‘here is an instance of this class, please keep hold of it and give it back to me when I ask’.
@Autowired says ‘please give me an instance of this class, for example, one that I created with an @Bean annotation earlier’.
**it becomes useful if you have the @Bean defined in one class, and the @Autowired in a different one.
On fields:
@NotBlank
@Size(min=1, max=255)
–> used whe adding mavn dependency: spring-boot-starter-validation
–> use class org.springframework.validation.Validator class
JPA Annotation
@Entity
Annotation on class–>in package domain –> the object that will be persisted to DB via JPA(Hibernate?)
Field annotations:
*for id:
@Id
@GeneratedValue(generator=”UUID”)
@GenericGenerator(name=”UUID”, strategy=”org.hibernate.id.UUIDGenerator”)
@Type(type=”org.hibernate.type.UUIDCharType”)
@Column(lenght=36, columnDefinition=”varchar”, updatable=false, nullable=false)
*for version:
@Version
*for date:
@CreationTimestamp
@Column(updatable=false)
@UpdateTimestamp
Sprin MVC annatations
On controller calsses:
@RequestMapping(“/api/v1/”)
@RestController
ON methods:
@GetMapping(produces={“application/json”},path=”beer”)
@GetMapping(“/path/{requestParam}”)
–> in parameters of the method (@PathVariable(“pathVariable”) Type localVarible, @RequestParam(value=showInventory,required=false) Boolean showInventory)
@PostMapping(“path”)
–> in method param
(@RequestBody @Validated BeetDTO beerDTO)
@PutMapping(“path”)