-
Notifications
You must be signed in to change notification settings - Fork 22
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
5주차 미션 / 서버 3조 이윤희 #52
base: step3-jdbc-start
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.
늦었지만 잘하셨습니다. 앞으로 더 힘내봅시다!! 👍
return "/home.jsp"; | ||
|
||
List<Question> questions = questionDao.findAll(); | ||
req.setAttribute("questions", questions); | ||
|
||
RequestDispatcher rd = req.getRequestDispatcher("/home.jsp"); | ||
rd.forward(req, resp); | ||
|
||
return null; |
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.
여기서 forward를 안해도 됩니다...! /home.jsp를 리턴하면 DispatcherServlet이 forward를 해줘요
public class ControllerUtils { | ||
|
||
public static Question getQuestionAndCheckAuthorization(HttpServletRequest req, QuestionDao questionDao) throws Exception { | ||
|
||
User user = (User) req.getSession().getAttribute("user"); | ||
if (user == null) { | ||
throw new IllegalStateException("로그인이 필요합니다."); | ||
} | ||
|
||
int questionId = Integer.parseInt(req.getParameter("questionId")); | ||
Question question = questionDao.findByQuestionId(questionId); | ||
|
||
if (!user.getUserId().equals(question.getWriter())) { | ||
throw new IllegalArgumentException("수정 권한이 없습니다."); | ||
} | ||
|
||
return 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.
개인적인 견해로는 Controller 클래스가 이 작업을 수행하는 것이 좋을 것 같아요
|
||
public class CreateQnaController implements Controller { | ||
|
||
private final QuestionDao questionDao = new QuestionDao(); |
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.
지금은 필드주입으로 충분하지만 장기적인 관점에서 보면 생성자 주입을 사용하는 것이 더 좋을 것 같네요
제 webMVC repository를 삭제해버려서,, 다시 올립니당 ㅜ