filmov
tv
How to use Spring JPA with PostgreSQL | Spring Boot
![preview_player](https://i.ytimg.com/vi/XHD3cJWiicA/maxresdefault.jpg)
Показать описание
In tradition approach, implementing Data Access Layer makes lots of boilerplate of code. Spring JPA is a part of Spring Data, helps us improve our codes and reduce efforts for development and maintenance. Spring JPA supports us the ways to write interface for repositories and custom finder methods, the implementation will be done automatically by Spring Framework.
The tutorial will introduce you how to use Spring JPA with PostgreSQL using Spring Boot.
I. Technology
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE
II. Overview
1. Goal
2. Project Structure
– Class Customer corresponds to entity and table customer, it should be implemented Serializable.
– CustomerRepository is an interface extends CrudRepository, will be autowired in WebController for implementing repository methods and custom finder methods.
– WebController is a REST Controller which has request mapping methods for RESTful requests such as: save. findall, findbyid, findbylastname.
3. Step to do
– Create Spring Boot project & add Dependencies
– Configure Spring JPA
– Create DataModel Class
– Create Spring JPA Repository Interface
– Create Web Controller
– Create PostGreSQL table
– Run Spring Boot Application & Enjoy Result
III. Practice
1. Create Spring Boot project & add Dependencies
2. Configure Spring JPA
3. Create DataModel Class
4. Create Spring JPA Repository Interface
5. Create Web Controller
6. Create PostGreSQL table
Open pdAdmin III, use SQL Editor and make a queryfor create customer table:
CREATE TABLE customer(
id BIGINT PRIMARY KEY NOT NULL,
firstname VARCHAR(20),
lastname VARCHAR(20)
);
7. Run Spring Boot Application & Enjoy Result
– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results:
Request 1
The browser returns Done and if checking database testdb with table customer, we can see some data rows has been added.
Request 2
Request 3
Request 4
IV. Source Code
================related keywork===============
#jpa postgresql example #jpapostgresqlexample
#jpa postgresql tutorial #jpapostgresqltutorial
#jpa hibernate postgresql #jpahibernatepostgresql
#spring boot jpa postgresql #springbootjpapostgresql
#spring datasource postgresql example #springdatasourcepostgresqlexample
#spring boot postgresql example #springbootpostgresqlexample
#spring boot jpa postgresql #springbootjpapostgresql
#spring jpa tutorial pdf #springjpatutorialpdf
#spring jpa hibernate tutorial or example #springjpahibernatetutorialorexample
#spring jpa tutorial for beginners #springjpatutorialforbeginners
#spring jpa repository tutorial #springjparepositorytutorial
#spring jpa example entitymanager #springjpaexampleentitymanager
#spring jpa integration example #springjpaintegrationexample
#spring jpa vs hibernate #springjpavshibernate
#spring boot jpa #springbootjpa
#spring jpa maven #springjpamaven
#spring boot jpa mysql #springbootjpamysql
#spring boot jpa hibernate #springbootjpahibernate
#spring boot jpa rest #springbootjparest
#spring-boot-starter-data-jpa #spring-boot-starter-data-jpa
#spring boot jpa example #springbootjpaexample
#spring boot postgresql datasource #springbootpostgresqldatasource
#spring boot postgres example #springbootpostgresexample
The tutorial will introduce you how to use Spring JPA with PostgreSQL using Spring Boot.
I. Technology
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE
II. Overview
1. Goal
2. Project Structure
– Class Customer corresponds to entity and table customer, it should be implemented Serializable.
– CustomerRepository is an interface extends CrudRepository, will be autowired in WebController for implementing repository methods and custom finder methods.
– WebController is a REST Controller which has request mapping methods for RESTful requests such as: save. findall, findbyid, findbylastname.
3. Step to do
– Create Spring Boot project & add Dependencies
– Configure Spring JPA
– Create DataModel Class
– Create Spring JPA Repository Interface
– Create Web Controller
– Create PostGreSQL table
– Run Spring Boot Application & Enjoy Result
III. Practice
1. Create Spring Boot project & add Dependencies
2. Configure Spring JPA
3. Create DataModel Class
4. Create Spring JPA Repository Interface
5. Create Web Controller
6. Create PostGreSQL table
Open pdAdmin III, use SQL Editor and make a queryfor create customer table:
CREATE TABLE customer(
id BIGINT PRIMARY KEY NOT NULL,
firstname VARCHAR(20),
lastname VARCHAR(20)
);
7. Run Spring Boot Application & Enjoy Result
– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results:
Request 1
The browser returns Done and if checking database testdb with table customer, we can see some data rows has been added.
Request 2
Request 3
Request 4
IV. Source Code
================related keywork===============
#jpa postgresql example #jpapostgresqlexample
#jpa postgresql tutorial #jpapostgresqltutorial
#jpa hibernate postgresql #jpahibernatepostgresql
#spring boot jpa postgresql #springbootjpapostgresql
#spring datasource postgresql example #springdatasourcepostgresqlexample
#spring boot postgresql example #springbootpostgresqlexample
#spring boot jpa postgresql #springbootjpapostgresql
#spring jpa tutorial pdf #springjpatutorialpdf
#spring jpa hibernate tutorial or example #springjpahibernatetutorialorexample
#spring jpa tutorial for beginners #springjpatutorialforbeginners
#spring jpa repository tutorial #springjparepositorytutorial
#spring jpa example entitymanager #springjpaexampleentitymanager
#spring jpa integration example #springjpaintegrationexample
#spring jpa vs hibernate #springjpavshibernate
#spring boot jpa #springbootjpa
#spring jpa maven #springjpamaven
#spring boot jpa mysql #springbootjpamysql
#spring boot jpa hibernate #springbootjpahibernate
#spring boot jpa rest #springbootjparest
#spring-boot-starter-data-jpa #spring-boot-starter-data-jpa
#spring boot jpa example #springbootjpaexample
#spring boot postgresql datasource #springbootpostgresqldatasource
#spring boot postgres example #springbootpostgresexample
Комментарии