이미 한 번 팀프로젝트를 진행해본 React와는 달리,
Spring은 이번에 처음 접해보는 프레임워크라 공부하는 시간이 좀 걸렸다. 아니 지금도 공부 중이다.
그래서 이번 주에는 진도를 많이 나가지는 못했고,
이 정도 했다.

dbdiagram.io 를 처음 써봤는데 굉장히 편하다!
MySQL workbench 이용해서 GUI로 간단하게 테이블을 만들고, 쿼리문을 내보낸 다음, 그걸 dbdiagram.io에서 import해서 몇 가지 문법 다른 것만 좀 수정하면 이렇게 그림으로 보여준다.
이 과정도 블로그에 포스팅했다 dbdiagram.io에 MySQL import하기
사용해본 MySQL과 PostgreSQL 중 고민했는데, 찾아보니 PostgreSQL은 복잡한 쿼리와 대용량 데이터에서 성능이 좋고 MySQL은 간단한 쿼리에서 더 성능이 좋다고 한다. 나는 복잡한 쿼리가 필요한 프로젝트가 아니니 MySQL을 선택하기로 한다.
GitHub Repository: https://github.com/SihyeonHong/EasiestCV

package EasiestCV.easiestCV.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name="users")
public class User {
@Id
@Column(name = "userid", nullable = false, unique = true)
private String userid;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "email", nullable = false, unique = true)
private String email;
// will be encoded later
@Column(name = "password", nullable = false)
private String password;
@Column(name = "img", nullable = true)
private String img;
@Column(name = "pdf", nullable = true)
private String pdf;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Tab> tabs = new ArrayList<>();
public User() {
}
/* Getters and Setters */
}
@Entity
@Table(name="tabs")
public class Tab {
@Id
@Column(name = "idtabs", nullable = false, unique = true)
private String idtabs;
@Column(name = "tabsorder", nullable = false)
private String tabsorder;
@Column(name = "tabsname", nullable = false)
private String tabsname;
@ManyToOne
@JoinColumn(name="fk_tabs_userid")
private User user;
@OneToMany(mappedBy = "tab", cascade = CascadeType.ALL)
private List<Content> contents = new ArrayList<>();
public Tab(){}
...
}
@Entity
@Table(name = "contents")
public class Content {
@Id
@Column(name = "idcontents", nullable = false, unique = true)
private String idcontents;
@Column(name = "contentsorder", nullable = false)
private String contentsorder;
@Column(name = "contentstype", nullable = false)
private String contentstype;
@Column(name = "contentscol", nullable = false)
private String contentscol;
@ManyToOne
@JoinColumn(name="fk_tabs_userid")
private User user;
@ManyToOne
@JoinColumn(name="idtabs")
private Tab tab;
public Content() {
}
...
}
@Repository
public interface UserRepository extends JpaRepository<User, String> {
}
@Service
public class UserService {
private final UserRepository userRepository;
@Autowired
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
// 비즈니스 로직 메서드들
}
@RestController
@RequestMapping("/users")
public class UserController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
// 웹 요청 처리 메서드들
}
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL), @ManyToOne @JoinColumn(name="fk_tabs_userid")로 설정한다는 것. Model 패키지의 코드들 참고. @RestController 와 @Controller의 차이 @Controller: 주로 View를 반환. JSP나 Thymeleaf 등 사용할 때. @RestController: @Controller + @ResponseBody . 주로 RESTful 웹 서비스를 개발할 때, 클라이언트에게 JSON 또는 XML 형태로 HTTP Response Body에 직접 데이터를 return할 때 사용된다.