Skip to content

노승현 1차 과제 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/doit/jpastudy2/repository/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package doit.jpastudy2.repository;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@Getter
public class Player {

@Id // PK임을 나타낸다.
@GeneratedValue(strategy = GenerationType.AUTO) // 자동 생성되는 값임을 나타낸다.
@Column(name = "player_id") // 컬럼명을 지정한다.
private Long id;

private String name;

private int teamId;

private String teamName;
Comment on lines +24 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CamelCase로 작성해주신 것 너무 좋습니다~!~


private String line;

@Builder // 빌더 패턴을 사용할 수 있게 한다.
public Player(String teamName, String name, String line, int teamId) {
this.teamName = teamName;
this.name = name;
this.line = line;
this.teamId = teamId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Long> {
public interface PlayerRepository extends JpaRepository<Player, Long> {

// 쿼리 메소드 패턴은 다음과 같다.
// [ ] = Optional
// ( ) = 조건
// find + [ ] + By + (조건)

// select * from Category
Category findByDescription(String description);
Player findByName(String name);

// select * from Category where type = ? and description = ?
Category findByTypeAndDescription(String type, String description);
Player findByNameAndLine(String name, String line);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@
@Entity
@NoArgsConstructor
@Getter
public class Category {
public class Team {

@Id // PK임을 나타낸다.
@GeneratedValue(strategy = GenerationType.AUTO) // 자동 생성되는 값임을 나타낸다.
@Column(name = "category_id") // 컬럼명을 지정한다.
@Column(name = "team_id") // 컬럼명을 지정한다.
private Long id;

// @Column(name = "type")이 생략된 경우 필드명이 컬럼명이 된다. snake_case로 변환된다.
private String type;
private String teamName;

// @Column(name = "description")이 생략된 경우 필드명이 컬럼명이 된다.
private String description;
private int ranking;

private int wins;

private double winningRate;

@Builder // 빌더 패턴을 사용할 수 있게 한다.
public Category(String description, String type) {
this.description = description;
this.type = type;
public Team(String teamName, int ranking, int wins, double winningRate) {
this.teamName = teamName;
this.ranking = ranking;
this.wins = wins;
this.winningRate = winningRate;
}
}
17 changes: 17 additions & 0 deletions src/main/java/doit/jpastudy2/repository/TeamRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package doit.jpastudy2.repository;

import org.springframework.data.jpa.repository.JpaRepository;

public interface TeamRepository extends JpaRepository<Team, Long> {

// 쿼리 메소드 패턴은 다음과 같다.
// [ ] = Optional
// ( ) = 조건
// find + [ ] + By + (조건)

// select * from Category
Team findByRanking(int ranking);

// select * from Category where type = ? and description = ?
Team findByTeamNameAndRanking(String teamName, int ranking);
}
108 changes: 0 additions & 108 deletions src/test/java/doit/jpastudy2/repository/CategoryRepositoryTest.java

This file was deleted.

Loading