spring notes

Tooling

Maven

Run:

./mvnw spring-boot:run

Gradle

./gradlew bootRun

Package manager and SDK

https://sdkman.io/sdks

REST

- Model (@Entity class decorator)

@Entity
class Availability {
    private @Id @GeneratedValue Long id;

- Controller

@RestController
public class AvailabilityController {
    private final AvailabilityRepository repository;
    private final AvailabilityModelAssembler assembler;

 

- Assembler

@Component
public class AvailabilityModelAssembler implements RepresentationModelAssembler<Availability, EntityModel<Availability>> {

    @Override
    public EntityModel<Availability> toModel(Availability availability) {
        return EntityModel.of(
            availability,
            linkTo(methodOn(AvailabilityController.class).one(availability.getId())).withSelfRel(),
            linkTo(methodOn(AvailabilityController.class).all()).withRel("availability")
        );

- Repository

public interface AvailabilityRepository extends JpaRepository<Availability, Long> {
    
}