spring-data-jpa

How to use spring-data-jpa

add depend


define entity

import jakarta.persistence.*;
import lombok.Data;

@Data
@Entity
@Table(name = "test1")
public class TestEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name")
    private String name;
}

define repository interface

import org.springframework.data.repository.CrudRepository;

public interface TestEntityRepository extends CrudRepository<TestEntity, Long> {
}

config connection

spring.datasource.url=jdbc:mysql://***
spring.datasource.username=***
spring.datasource.password=***
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

How spring-jpa works

How to use spring-data-jdbc

examples