Introduction to Displaying Data
Learn how to generate random users in the database.
We'll cover the following
Generate random users
The first thing we need is a few users in our database for testing. We could create a database script to do that, but it’s easier to write a simple Java class that can create things in a loop.
Let’s start by creating a CommandLineRunner
implementation. Spring will run any such beans at the startup of the application. By only enabling the bean when the init-db
profile is active, we can toggle if the database should be populated at startup or not.
This is the code for the DatabaseInitializer
:
Get hands-on with 1400+ tech skills courses.