Spring Boot with DB Migration (2 of 2)


This article is the continuation article of Spring Boot with DB Migration (1 of 2).

Build Application

From now on, create Spring Boot application. Let’s create files in the follwong structure.

Add configuration

Update application.properties and DemoApplication class.

Add database configuration to the application.properties.

Add @EnableJpaAuditing annotation to DemoApplication class. It is used for timestamp auto updating.

Entity

Create an entity, which represents the record in the database. Create the file of the class , Task, as domain/task/Task.kt.

@EntityListeners, @CreateDate and @LastModifiedDate are added for auto updating.

Repository

Create the repository interface, TaskRepository, for Task, as domain/task/TaskRepository.kt.

View template

Create the view template, which is resources/templates/task/index.html.

Controller

Create the controller, TaskController, as presentation/task/TaskController.kt.

Run the application

Execute ./gradlew bootrun, and after awhile, you can see the page on the browser. Please access to http://localhost:8080/task. And you can add and remove tasks.

Figure: 2 tasks are added.

The code of this demo project is on GitHub.