-
Notifications
You must be signed in to change notification settings - Fork 379
[JDBC 라이브러리 구현하기 - 1, 2단계] 현구막(최현구) 미션 제출합니다. #34
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
Changes from all commits
22072d5
d9cfaa1
6d62613
80140bd
c158788
2d3fb19
91695f5
acf57da
d9225b1
54898b1
8fab7ae
4e4415a
4b17405
308315d
dbf9765
1f0c15d
37087bf
832fb74
e85d4d8
85c9ffa
a6111c0
f1b96c1
e0e3b96
86eb046
9cb151c
a7fa076
7defbd9
92a2d11
ced9630
4d36e3e
5d1022d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,10 @@ | ||
| # jwp-dashboard-jdbc | ||
|
|
||
| - [x] Connection 생성 자동으로 해주기 | ||
| - [x] PreparedStatement 자동으로 준비 및 실행 해주기 | ||
| - [x] ResultSet 만들어주기 | ||
| - [x] JdbcTemplate 사용자가 쿼리와 rowMapper 만 전달해서 매핑 자동화 | ||
| - [x] 예외처리 (커스텀 익셉션) | ||
| - [ ] 트랜잭션 관리 (...??) | ||
| - [x] Connection, Statement, ResultSet close (try-with-resource 사용) | ||
| - [x] Insert 아이디 발급 편의를 위해 SimpleJdbcInsert 만들어보기 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,33 @@ | ||
| package com.techcourse; | ||
|
|
||
| import com.techcourse.config.DataSourceConfig; | ||
| import com.techcourse.support.jdbc.init.DatabasePopulatorUtils; | ||
| import jakarta.servlet.ServletContext; | ||
| import jakarta.servlet.ServletRegistration; | ||
| import nextstep.mvc.DispatcherServlet; | ||
| import nextstep.mvc.controller.asis.ControllerHandlerAdapter; | ||
| import nextstep.mvc.controller.tobe.AnnotationHandlerMapping; | ||
| import nextstep.mvc.controller.tobe.HandlerExecutionHandlerAdapter; | ||
| import nextstep.mvc.controller.AnnotationHandlerAdapter; | ||
| import nextstep.mvc.controller.AnnotationHandlerMapping; | ||
| import nextstep.mvc.exception.ComponentContainerException; | ||
| import nextstep.web.ComponentContainer; | ||
| import nextstep.web.WebApplicationInitializer; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class AppWebApplicationInitializer implements WebApplicationInitializer { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(AppWebApplicationInitializer.class); | ||
| private static final Logger LOG = LoggerFactory.getLogger(AppWebApplicationInitializer.class); | ||
| private static final String BASE_PACKAGE = "com.techcourse"; | ||
|
|
||
| @Override | ||
| public void onStartup(ServletContext servletContext) { | ||
| final DispatcherServlet dispatcherServlet = new DispatcherServlet(); | ||
| dispatcherServlet.addHandlerMapping(new ManualHandlerMapping()); | ||
| dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping("com.techcourse.controller")); | ||
|
|
||
| dispatcherServlet.addHandlerAdapter(new ControllerHandlerAdapter()); | ||
| dispatcherServlet.addHandlerAdapter(new HandlerExecutionHandlerAdapter()); | ||
| dispatcherServlet.addHandlerMapping(new AnnotationHandlerMapping(BASE_PACKAGE)); | ||
| dispatcherServlet.addHandlerAdapter(new AnnotationHandlerAdapter()); | ||
|
|
||
| final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet); | ||
| dispatcher.setLoadOnStartup(1); | ||
| dispatcher.addMapping("/"); | ||
|
|
||
| log.info("Start AppWebApplication Initializer"); | ||
| LOG.info("Start AppWebApplication Initializer"); | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| package com.techcourse.config; | ||
|
|
||
| import javax.sql.DataSource; | ||
| import nextstep.web.annotation.Configuration; | ||
| import nextstep.web.annotation.Initialize; | ||
| import org.h2.jdbcx.JdbcDataSource; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| @Configuration | ||
| public class DataSourceConfig { | ||
|
|
||
| private static javax.sql.DataSource INSTANCE; | ||
| private static DataSource INSTANCE; | ||
|
|
||
| public static javax.sql.DataSource getInstance() { | ||
| private DataSourceConfig() {} | ||
|
|
||
| @Initialize | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 단순히
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public static DataSource getInstance() { | ||
| if (Objects.isNull(INSTANCE)) { | ||
| INSTANCE = createJdbcDataSource(); | ||
| } | ||
|
|
@@ -22,6 +29,4 @@ private static JdbcDataSource createJdbcDataSource() { | |
| jdbcDataSource.setPassword(""); | ||
| return jdbcDataSource; | ||
| } | ||
|
|
||
| private DataSourceConfig() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.techcourse.controller; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import nextstep.mvc.view.JspView; | ||
| import nextstep.mvc.view.ModelAndView; | ||
| import nextstep.web.annotation.Controller; | ||
| import nextstep.web.annotation.RequestMapping; | ||
| import nextstep.web.support.RequestMethod; | ||
|
|
||
| @Controller | ||
| public class ForwardController { | ||
|
|
||
| @RequestMapping(value = "/", method= RequestMethod.GET) | ||
| public ModelAndView page(HttpServletRequest request, HttpServletResponse response) { | ||
| return new ModelAndView(new JspView("/index.jsp")); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,59 @@ | ||
| package com.techcourse.controller; | ||
|
|
||
| import com.techcourse.domain.User; | ||
| import com.techcourse.repository.InMemoryUserRepository; | ||
| import com.techcourse.controller.request.RegisterRequest; | ||
| import com.techcourse.exception.DuplicateAccountException; | ||
| import com.techcourse.service.RegisterService; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import nextstep.mvc.view.JspView; | ||
| import nextstep.mvc.view.ModelAndView; | ||
| import nextstep.web.annotation.Autowired; | ||
| import nextstep.web.annotation.Controller; | ||
| import nextstep.web.annotation.RequestMapping; | ||
| import nextstep.web.support.RequestMethod; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @Controller | ||
| public class RegisterController { | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.POST) | ||
| public ModelAndView register(HttpServletRequest request, HttpServletResponse response) { | ||
| final User user = new User(2, | ||
| request.getParameter("account"), | ||
| request.getParameter("password"), | ||
| request.getParameter("email")); | ||
| InMemoryUserRepository.save(user); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
| private static final Logger LOG = LoggerFactory.getLogger(RegisterController.class); | ||
|
|
||
| private final RegisterService registerService; | ||
|
|
||
| @Autowired | ||
| public RegisterController(RegisterService registerService) { | ||
| this.registerService = registerService; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.GET) | ||
| public ModelAndView view(HttpServletRequest request, HttpServletResponse response) { | ||
| public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { | ||
| return new ModelAndView(new JspView("/register.jsp")); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/register", method = RequestMethod.POST) | ||
| public ModelAndView save(HttpServletRequest request, HttpServletResponse response) { | ||
| try { | ||
| RegisterRequest registerRequest = getRegisterRequest(request); | ||
| registerService.registerUser(registerRequest); | ||
|
|
||
| LOG.debug("Register Success!!"); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/index.jsp")); | ||
| } catch (DuplicateAccountException e) { | ||
| LOG.debug("Register Failed..."); | ||
|
|
||
| return new ModelAndView(new JspView("redirect:/409.jsp")); | ||
| } | ||
| } | ||
|
|
||
| private RegisterRequest getRegisterRequest(HttpServletRequest request) { | ||
| String account = request.getParameter("account"); | ||
| String password = request.getParameter("password"); | ||
| String email = request.getParameter("email"); | ||
|
|
||
| LOG.debug("Register Request => account: {}, email: {}", account, email); | ||
|
|
||
| return new RegisterRequest(account, password, email); | ||
| } | ||
| } |
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.
해당 클래스에 불필요한 import 문들이 있는데 제거하면 좋을 것 같아요 👀
Uh oh!
There was an error while loading. Please reload this page.
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.
앗... 꼼꼼한 리뷰 감사합니다 ㅠㅠ 요즘 120자 제한을 두고도 가독성을 위해 조금씩 넘겨서 코드를 짜다보니
코드 리포맷팅을 사용하면 코드 라인이 넘어가는게 싫어서 리포맷팅을 잘 안누르게 되네요.. 이상한 버릇이 생겨버렸어요..
넘길 땐 넘길 줄 알아야 하는데!!!!!