Repository to explain Spring Data JPA concepts
Explore the article »
Report Bug
·
Request Feature
<!-- Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
Access the application.properties file to configure the database.
# Database URL
spring.datasource.url=jdbc:mysql://localhost:3306/shinobidatabase
# Database User and Password
spring.datasource.username=root
spring.datasource.password=hokage
# Driver -> MySQL
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
# Show SQL in terminal
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
# DDL Strategy - create, create-drop, update, validate, none
spring.jpa.hibernate.ddl-auto=update
# Convert Camelcase to Database Default
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
Using the sql/populate.sql file, we can populate the database with some data.
spring.jpa.properties.hibernate.hbm2ddl.import_files=sql/populate-database.sql
Running database using docker-compose file
docker-compose up -d
mvn spring-boot:run
Example of the response:
[
{
"id": 1,
"name": "Naruto",
"village": "KONOHAGAKURE"
},
{
"id": 2,
"name": "Sasuke",
"village": "KONOHAGAKURE"
},
{
"id": 3,
"name": "Sakura",
"village": "KONOHAGAKURE"
},
{
"id": 4,
"name": "Killer B",
"village": "KUMOGAKURE"
}
]
@jjeanjacques10 |
---|