1. Add H2, JPA dependencies
In case you are using gradle you can add the following to your build.gradle
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
2. H2 jpa configration
set the jpa and H2 configs in
application.properties
spring.h2.console.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:file:./data/dcbappA
spring.datasource.username=user
spring.datasource.password=
3. Creating Entity
This entity will be added as a new table in the database.
model > Customer.java
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String Address;
private Long phone;
}
4. Creating repository
Repository extendss the JPA to provide prebuild queries.
repository > CustomerRepository
@Repository
public interface CustomerRepository extends JpaRepository<Customer,Long> {
}
Latest comments (0)