0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SpringBootAdvent Calendar 2023

Day 15

【Spring Data JPA】Database操作②

Posted at

カスタムクエリ

↓の基本クエリにない場合は自分でカスタムすることもできる

名前がjohnのユーザーのレコードを取得

Service.java
public List<User> getUser(String name){
    return userRepository.findByName(name);
}

getUserメソッドのメソッド名は何でもいいです


名前がwillianで年齢が20歳のユーザーを取得

Service.java
public List<User> getUser(String name, int age){
    userRepository.findByNameAndAge(name, age);
}

getUserメソッドのメソッド名は何でもいいです


ユーザーがアプリ内トラッキングを許可しているかどうかを取得

Service.java
public boolean getTrackingAllow(int id){
    return userRepository.isTrackingAllowById(id);
}

※戻り値がboolean型の時はisから始まります

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?