반응형
[Spring JPA] 1. 체크리스트 만들기 - 초기 설정하기
[Spring JPA] 2. 체크리스트 만들기 - Entity 설정하기
[Spring JPA] 3. 체크리스트 만들기 - Controller 설정하기
[Spring JPA] 4. 체크리스트 만들기 - Service 설정하기
Checklist Repository
@Repository
public interface ChecklistRepository extends JpaRepository<ChecklistEntity, Integer> {
Optional<ChecklistEntity> findBycIdAndState(int cId, int state);
Optional<ChecklistEntity> findBycId(Integer cId);
}
Item Respository
@Repository
public interface ItemRepository extends JpaRepository<ItemEntity, Integer> {
List<ItemEntity> findAllByChecklist(ChecklistEntity checklist);
Optional<ItemEntity> findByIdAndChecklist_cId(int id, int cId);
Optional<ItemEntity> findByIdAndChecklist(int iId, ChecklistEntity checklist);
Optional<ItemEntity> findById(int id);
}
Checklist DTO
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChecklistRequest {
private String title;
private List<ItemRequest> items;
}
@Getter
@Setter
public class ChecklistResponse {
String title;
int cId;
List<ItemResponse> items;
public ChecklistResponse() {
// 기본 생성자
}
// 생성자에 매개변수로 title, cId를 받아와서 초기화하고 items를 빈 리스트로 초기화
public ChecklistResponse(String title, int cId) {
this.title = title;
this.cId = cId;
this.items = new ArrayList<>(); // 빈 리스트로 초기화
}
// 생성자에 ChecklistEntity를 받아와서 ChecklistResponse 객체로 변환하는 코드 추가
public ChecklistResponse(ChecklistEntity checklistEntity) {
this.title = checklistEntity.getTitle();
this.cId = checklistEntity.getCId();
}
}
Item DTO
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ItemRequest {
private String name;
private Long itemOrder;
private Boolean ischecked;
private int cId;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@Setter
public class ItemResponse {
private Long iId;
private String name;
private Long itemOrder;
private Boolean isChecked; // 변수 이름 변경
private int cId;
public ItemResponse(Long iId, String name, Boolean isChecked, int cId) {
this.iId = iId;
this.name = name;
this.isChecked = isChecked;
this.cId = cId;
}
public ItemResponse(Long iId, String name, Boolean isChecked) {
this.iId = iId;
this.name = name;
this.isChecked = isChecked;
}
// setter 메서드 추가
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}
}
반응형
'Develop > Spring Boot' 카테고리의 다른 글
[Spring JPA] 4. 체크리스트 만들기 - Service 설정하기 (0) | 2023.08.28 |
---|---|
[Spring JPA] 3. 체크리스트 만들기 - Controller 설정하기 (0) | 2023.08.28 |
[Spring JPA] 2. 체크리스트 만들기 - Entity 설정하기 (0) | 2023.08.28 |
[Spring JPA] 1. 체크리스트 만들기 - 초기 설정하기 (0) | 2023.08.25 |
[Error] HikariPool-1 - Thread starvation or clock leap detected (0) | 2023.08.05 |