-
Notifications
You must be signed in to change notification settings - Fork 21
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
7주차 미션 / 서버 1조 강희진 #2
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7주차 미션도 고생 많으셨습니다!
스프링으로 프로젝트를 해보신 경험 덕분인지 기본 기능을 잘 이해하고 계신 것 같아요😊
이번 주까지 배운 스프링의 동작 원리를 앞으로 남은 3주 동안 잘 활용하시면 좋을 것 같아요!
마지막까지 화이팅!!! 🔥🔥
// public HomeController(QuestionRepository questionRepository) { | ||
// this.questionRepository = questionRepository; | ||
// } | ||
|
||
/** | ||
* TODO: showHome |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기능을 모두 구현한 후에 TODO 주석은 지우는 것이 좋습니다:)
return mav.addObject("users", userRepository.findAll()); | ||
} | ||
return new ModelAndView("redirect:/user/loginForm"); | ||
//리다이렉트를 모델앤뷰로..?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelAndView를 통해 리다이렉트 하는 것도 가능하지만,
반환값을 String 타입으로 변경하고 파라미터로 Model을 추가한 후에,
- 로그인 되어있는 사용자인 경우 model에 값을 담아서 "/user/list" 뷰 이름을 반환하고,
- 로그인 되어있지 않은 경우 "redirect:/user/loginForm" 로 리다이렉트하는 것이 더 자연스러울 것 같습니다!
/** | ||
* TODO: showQuestionForm | ||
*/ | ||
@GetMapping("/form") | ||
public ModelAndView showQuestionForm(HttpServletRequest request){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model에 담을 데이터가 없는 경우에는 String으로 뷰 이름만 반환하는게 더 좋을 것 같아요:)
|
||
question.setCountOfAnswer(0); | ||
questionRepository.insert(question); | ||
log.info(String.valueOf(question)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.valueOf(question)
보다는 question.toString()
을 사용하는 것이 더 직관적입니다
questionRepository.insert(question); | ||
log.info(String.valueOf(question)); | ||
|
||
System.out.println("saved question id= " + question.getQuestionId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
표준 출력과 로그에 대해서도 공부하시면 좋을 것 같아요!
(둘의 차이점, 왜 로그 사용을 지향해야 하는지 등등)
} | ||
|
||
Question question = questionRepository.findByQuestionId(Integer.parseInt(questionId)); | ||
if (!question.isSameUser(loggedInUser)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 코드를 잘 활용해서 구현하셨네요!👍🏻👍🏻
코드리뷰 부탁드립니당 🥰🤗