프로젝트 소개 및 배경
: 기존의 쇼핑몰을 MVC패턴으로 구성해뒀던 것을 sts를 활용하여 스프링 구조로 변경하여 코드의 유지보수성을 향상 시키고자 함.
변경된 부분
- 기존의 JDBC 방식을 Mybatis로 변경함.
- 기존 Servlet을 Spring의 @어노테이션을 활용하여 Spring MVC구조로 변경함.
구조 변경 계기 및 필요성
- 코드의 유지보수성 향상
- 의존성 주입
- 트렌젝션을 활용
- 비즈니스 로직 구현에 집중
변경된 아키텍처 및 구조
변경 전 )
변경 후 )
의존성 주입 및 IoC 컨테이너
- Java 기반 설정
Java 클래스를 사용하여 빈들을 정의하고 구성함.
@Controller
@RequestMapping("/cart")
public class CartController {
@Autowired
private CartService cartService;
/** 장바구니 목록 보기 **/
@RequestMapping(value = "/cartList", method = RequestMethod.GET)
public String cartList(HttpServletRequest request, Model model) {
HttpSession session = request.getSession();
MemberVO loginUser = (MemberVO) session.getAttribute("loginUser");
if (loginUser == null) {
return "redirect:/members/login_form.do";
} else {
model.addAttribute("cartList", cartService.getCartListForUser(loginUser));
}
return "mypage/cartList";
}
문제 해결 경험
: 프로젝트 구조 변경 과정에서 마주친 어려움이나 문제점, 그리고 이를 어떻게 해결했는지에 대한 경험
결과 및 성과
- Spring을 활용하여 구조를 변경하자 유지보수가 용이해짐.
- 객체 생성과 같은 일을 스프링에게 위임하여 이번 프로젝트에서는 비즈니스 로직에 조금 더 초점을 맞춰 개발할 수 있게 됨.
- 코드 가독성이 향상 됨.
Spring 구조로 변경
기존 Servlet을 Spring의 @어노테이션을 활용하여 Spring MVC구조로 변경함.
private void doHandle(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String url = "";
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
String action = request.getPathInfo();
System.out.println("action:" + action);
if(action.equals("/contract.do")) { // 개인정보동의 페이지
url = "/member/contract.jsp";
request.getRequestDispatcher(url).forward(request, response);
}
else if (action.equals("/join_form.do")) { // 개인정보 동의 유무를 넘겨줌
url = "/member/join.jsp";
request.getRequestDispatcher(url).forward(request, response);
}
@Controller
@RequestMapping("/members")
public class MemberController {
@Autowired
private MemberService memberService;
/** 개인정보동의 페이지 **/
@RequestMapping(value = "/contract", method = RequestMethod.GET)
public String contract() throws Exception {
return "/member/contract";
}
/** 개인정보 동의 유무를 넘겨줌 **/
@RequestMapping(value = "/join_form", method = RequestMethod.POST)
public String joinForm() throws Exception {
return "/member/join";
}
}
'🚀 부트캠프 - PLAYDATA' 카테고리의 다른 글
[Spring] 스프링 AOP 기능 (0) | 2023.08.13 |
---|---|
[PLAYDATA / JSP] for문 사용해서 목록 리스트를 출력해서 전송 (0) | 2023.07.18 |
Thread (0) | 2023.07.01 |
인터페이스 (0) | 2023.06.29 |
상속 (0) | 2023.06.29 |