Summary
Highlights
Models are the 'M' in MVC and are plain old Java classes (POJOs) that primarily contain fields. These fields represent the structure of data. When integrated with Spring Data, these POJOs are transformed into database tables, with each field becoming a column.
Spring Data JPA automatically converts model classes into database tables. Each field in the POJO (e.g., ID, title, photo URL, content, created date) corresponds to a column in the database table, similar to an Excel spreadsheet without the GUI.
To enable Spring Data JPA to recognize a class as a model, it must be annotated with @Entity. Each entity requires a unique identifier, marked with @Id, which acts as the primary key. The @GeneratedValue annotation ensures that this ID is automatically incremented and unique for each new entry.
The video demonstrates how to organize models by creating a 'models' package in IntelliJ. A 'Club' Java class is then created with fields such as 'id', 'title', 'photoUrl', 'content', 'createdOn', and 'updatedOn'. The fields 'createdOn' and 'updatedOn' use 'LocalDateTime' type.
Lombok annotations like @Data, @NoArgsConstructor, and @AllArgsConstructor are used to automatically generate getters, setters, and constructors, reducing boilerplate code. Critical JPA annotations such as @Entity, @Table(name="clubs"), @Id, @GeneratedValue, @CreationTimestamp, and @UpdateTimestamp are added to define the model's behavior and database mapping.
After setting up the model, the application is rerun. Spring Data JPA automatically creates the 'clubs' table in the database based on the 'Club' model. The video verifies the table's creation and structure, confirming that all defined fields are correctly mapped as columns.