1. 1차 Project 관련 글 : 230202
1) DB 설계 :
a. 필수 :
- Member/Stuff/list.html라고 하면, MEMBER 테이블 필요, STUFF 테이블 필요, 참여방 관련 테이블이 따로 필요하다. 총 3중 연결 DB!
- MEMBER 테이블은 회원 정보 관련 테이블이다.
- STUFF 테이블은 글 등록 관련 테이블이다.(여기에 카테고리 테이블을 연결시켜줘야 하는가? 카테고리를 STUFF 테이블에 넣어줘도 된다.)
- 참여하는 방 관련한 테이블이 따로 필요한가? 참여한 사람에 대한 정보가 한가? 참여한 사람에 관해서
b. 선택 : 기본적인 DB에 칼럼을 추가하는 것이 아니라 따로 DB로 빼서 관리해야 하는 이유는?
- 카테고리 : 카테고리를 넣으려면 카테고리 DB를 따로 만들어야 한다.(글 등록 시, 따로 페이지 만들기 보다는 모달 팝업으로 구현하자!)
- 참여하는 방 : 참여한 사람에 대한 정보가 한가? 참여한 사람에 관해서
c. 추가 :
- ‘모집중’ 관련 로직 : 모집중인 방의 인원이 가득 차면, 모집끝으로 변경하고 중간에 인원수가 빠지면 다시 모집중으로 변경된다.
- ‘방에 참여한 사람의 정보’ : 방에 참여한 사람의 정보가 필요한지?? 나중에 그 사람 프로필 눌러서 그 사람의 정보를 보려면 필요할 수 도 있을거 같다. // 보고싶은 사람의 프로필을 보는 창은 필요한 것 같다. 상세페이지에서 참여중인 사람을 눌렀을 때, 연결
- 새로운 DB가 필요하다. Member/Stuff/participationProfile/list.html 순서이다. 방에 참여한 사람의 정보에 관한 디렉토리 경로!
2) 기획 정리, 도메인 정리 : 230303
-
2차 프로젝트가 시작되기 전에 개발에 필요한 모든 페이지가 퍼블리싱되면 좋다.
-
적어도 ‘추가 기능에 대한 기획’은 모두 되어 있어야 한다.
3) Front-Controller 설계 시, 에러 : 230315
a. @RequestParam 개념 :
- @RequestParam은 Entity(Member)가 필요 없어도 view에서 값을 넘겨 받을 수 있다.
- Entity는 보통 DB에서 값을 받기 위해 그릇같은 역할로서 존재한다.
b. redirect 개념 중요!!
- @PostMapping에서 redirect하면 html form 태그의 action 속성은 필요 없다.
- html의 form 태그 action 속성이 우선 되기 때문이다.
- action 속성을 redirect에 의해 서버에서 처리해주기 때문이다.
- redirect를 사용할 때는 “/”를 쓰지 않는다.
c. 중요!! : @PostMapping가 HttpServletRequest를 가지고 있는지? 개념 :
-
@PostMapping에HttpServletRequest가 포함되는 것이 아니라 클라이언트 요청 처리 방법으로서 4대 저장소에 저장하여 처리하기 위해 추가로 써줘야 한다! + 쿠키도 있다. -
반대로 서버에서 보내는 것이
Model객체가 있다.
d. DTO 정리 :
- 하지만 Entity는 커맨드 객체와 차이점이 있다!**
- 커맨드 객체는 DTO 객체이며 가독성을 높여준다.
- 중요 : 자동으로 바인딩 해주기 위해서 DTO를 사용하는 쪽의 메서드에서 요청 파라미터의 속성값(변수명)이랑 DTO 객체의 속성값(객체가 가지고 있는 변수명)이랑 일치해야 하고 setter도 가지고 있어야 한다.**
- 실습 코드 :
package com.modeul.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/")
public class MemberController {
@GetMapping("login")
public String login() {
return "login.jsp";
}
@GetMapping("signup")
public String signup() {
return "sign-up.jsp";
}
@PostMapping("signup")
public String signup(
@RequestParam(name="uid") String uid,
@RequestParam(name="password") String password,
@RequestParam(name="repassword") String repassword,
@RequestParam(name="name") String name,
@RequestParam(name="email") String email,
@RequestParam(name="reemail") String reemail) {
// @RequestParam은 Entity(Member)가 필요 없어도 된다.
System.out.printf("uid : %s, pw: %s, rpw: %s", uid, password, repassword);
return "redirect:login";
// redirect 개념 중요!!
// 이렇게 redirect하면 html form 태그의 action 속성은 필요 없다.
// 서버에서 처리해주기 때문
}
}
<!-- ----------------------------------------------------------- -->
<main class="m-t-31px">
<!-- flex 시작 -->
<div class="sign-up-container">
<!-- form 태그의 action 속성이 필요 없다. -->
<form method="post">
<div class="input-field-2">
<label for="uid" class="uid-label">
<span class="d-none">uid</span>
<input type="text" id="uid" name="uid" class="input-text-2" placeholder="아이디를 입력해주세요.">
</label>
</div>
<div class="input-field-2 m-t-1">
<label for="password" class="password-label">
<span class="d-none">pw</span>
<input type="text" id="password" name="password" class="input-text-2" placeholder="비밀번호를 입력해주세요.">
</label>
</div>
<div class="input-field-2 m-t-1">
<label for="password-confirm" class="password-confirm-label">
<span class="d-none">pw-confirm</span>
<input type="text" id="password-confirm" name="repassword" class="input-text-2" placeholder="비밀번호를 다시 입력해주세요.">
</label>
</div>
<div class="input-field-2 m-t-1">
<label for="name" class="name-label">
<span class="d-none">name</span>
<input type="text" id="name" name="name" class="input-text-2" placeholder="이름을 입력해주세요.">
</label>
</div>
<div class="input-field-2 m-t-1">
<label for="email" class="email-label">
<span class="d-none">email</span>
<input type="text" id="email" name="email" class="input-text-2" placeholder="이메일을 입력해주세요.">
<input class="btn-post" id="btn-post" type="button" value="전송">
</label>
</div>
<div class="input-field-2 m-t-1">
<label for="email" class="email-confirm-label">
<span class="d-none">email-confirm</span>
<input type="text" id="reemail" name="reemail" class="input-text-2" placeholder="이메일 인증번호를 입력해주세요.">
<input class="btn-auth" id="btn-auth"type="button" value="확인">
</label>
</div>
<div class="d-fl-jf m-t-69px">
<input class="btn-3" type="submit" value="가입하기">
</div>
</form>
</div>
</main>
</div>
</body>
</html>