sungwon-097 / Spring_Security

1 stars 0 forks source link

JPA query method #6

Open sungwon-097 opened 1 year ago

sungwon-097 commented 1 year ago
// UserEntity.java
@Entity
@Data
public class User {
    @Id // primary Key
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String username;
    private String password;
    private String email;
    private String role; // ROLE_USER, ROLE_ADMIN
    @CreationTimestamp
    private Timestamp crateDate;
}

// UserRepository.interface
public interface UserRepository extends JpaRepository<User, Integer> { // User 의 primaryKey 는 Integer

    // findBy 규칙, Username 문법
    // select * from user where username = ?
    public User findByUsername(String username);

    // findBy 규칙, Email 문법
    // select * from user where email = ?
    public User findByEmail(String email);
}

Go to Extra Document