Accessing Data with Spring Data JPA and MySQL

Dependencies

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 
runtimeOnly 'mysql:mysql-connector-java'

Configuring Database Connection Properties

# MySQL connection properties 
spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/rest-service spring.datasource.username=root
spring.datasource.password=root@pass

Create User Model Class

Create a Repository

Create Request File

Create User Controller

Run the Application

java -jar target/rest-service-0.0.1-SNAPSHOT.jar
java -jar build/libs/rest-service-0.0.1-SNAPSHOT.jar

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CodingHub

CodingHub

Coding Hub — Learn & Build Your Career