Creating New Components
Entity Model
This Java class is a JPA Entity that extends AbstractModel. This class represents a table in your database. Each instance corresponds to a row within the table.
Basic Entity Structure
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class ExampleEntity extends AbstractModel {
private String content;
}Key Annotations:
@Getterand@Setter: Lombok annotations that auto-generate getter and setter methods@SuperBuilder: Enables the builder pattern for this class and its subclasses@NoArgsConstructorand@AllArgsConstructor: Generate constructors@Entity: JPA annotation marking the class as a persistable entity
Controller
Controllers handle HTTP requests and define API endpoints.
Basic Controller Structure
@RestController
@RequestMapping("/v1/example")
@ExposesEntity(ExampleEntity.class)
@Tag(name = "ExampleController", description = "Example for implementing openAPI")
public class ExampleController
extends DefaultRestController<
ExampleEntity, ExampleEntityDto, ExampleRepresentation, ExampleSpecification> {
public ExampleController(ExampleService service) {
super(service);
}
}Key Annotations:
@RestController: Marks the class as a RESTful controller@RequestMapping: Maps web requests to this controller@ExposesEntity: Associates the controller with an entity resource class@Tag: Provides OpenAPI 3 metadata
The controller extends DefaultRestController, which provides standard CRUD operations out of the box.
Service Layer
Services contain the business logic of your application.
@Service
public class ExampleService
extends DefaultAssemblingEntityService<
ExampleEntity, ExampleEntityDto, ExampleRepresentation> {
public ExampleService(
ExampleRepository repository,
ExampleAssembler assembler) {
super(repository, assembler);
}
}Repository
Repositories handle database operations.
@Repository
public interface ExampleRepository extends BaseRepository<ExampleEntity> {
// Custom query methods can be added here
}Complete Component Creation Workflow
- Create the Entity - Define your database model
- Create the DTO - Define the data transfer object for input
- Create the Representation - Define the output format
- Create the Repository - Database access layer
- Create the Assembler - Convert between Entity, DTO, and Representation
- Create the Service - Business logic layer
- Create the Controller - REST API endpoints
- Add Tests - Unit and integration tests for your component