spring 2
AOP (Aspect Oriented Programming)
- 관심사의 분리를 통해서 소프트웨어의 모듈성을 향상시키고자 하는 프로그래밍 패러다임
 - 소스코드 레벨에서 관심사의 모듈화를 지향하는 프로그래밍 방법이나 도구를 포함
 - 횡단관심(Cross-cutting concern)
    
- 어플리케이션의 다양한 관점(point)에 영향을 미치는 기능
 - aspect라고 하는 특별한 객체로 모듈화가 가능함
 - 핵심관심 : 기능정의 -> 메서드
 
 - Aspect
    
- 횡단관심사의 동작과 그 횡단괌심사를 적용하려는 소스 코드에서의 위치를 모아둔 것
 - 하나 이상의 Advice(동작)과 Pointcut(동작을 적용하는 조건)을 조합한 것
 
 - Joinpoint
    
- Advice가 실행하는 동작을 끼워넣을 수 있는 때를 의미
 - 스프링에서는 메서드가 호출될 때와 메서드가 원래 호출한 곳으로 돌아갈 때가 어드바이스를 끼워넣을 수 있는 조인포인트이다
 
 - Advice
    
- Joinpoint에서 실행되는 코드
 - 보안, 로깅, 트랜잭션 관리 등의 코드가 기술됨
 
 - Pointcut
    
- Joinpoint와 Advice의 중간에 있으면서 처리가 조인포인트에 이르렀을 때 Advice를 호출할지 선별
 
 
DispatcherServlet
- 제일 앞에서 서버로 들어오는 모든 요청을 먼저 받아서 처리하는 서블릿
 - web.xml에 등록
 
MVC (Model View Controller) 패턴
- 어플리케이션의 확장을 위해 Model, View, Controller 세가지 영역으로 분리
 - 컴포넌트의 변경이 다른 영역 컴포넌트에 영향을 미치지 않음
 - 컴포넌트 간의 결합도가 낮아 프로그램 수정이 용이
 
장점
- 화면과 비즈니스 로직을 분리해서 작업 가능
 - 영역별 개발로 인하여 확장성이 뛰어남
 - 표준화된 코드를 사용하므로 공동작업이 용이하고 유지보수성이 좋음
 
단점
- 개발과정이 복잡해 초기 개발속도가 늦음
 - 초보자가 이해하고 개발하기에 다소 어려움
 
controller 등록하기
- 
    
컨트롤러로 사용할 클래스에
@Controller어노테이션 달기 - 
    
servlet-context.xml에 컨트롤러 등록하기- 
        
<context:component-scan base-package="컨트롤러로 등록한 클래스가 있는 패키지명"></context:component-scan> 
 - 
        
 - 
    
메소드에 달린
@RequestMapping()은 서블릿에서@WebServlet()과 같은 역할을 한다- 
        
@Controller public class MainController { @RequestMapping("method1") void m1() { } } 
 - 
        
 - 
    
return 값을 String으로 보내는 것은 forward와 같다
- 
        
@Controller public class MainController { @RequestMapping("method2") String m2() { return "home"; } } 
 - 
        
 - 
    
redirect의 경우 리턴 문자열 앞에 “redirect:/”을 붙여준다
 - 
    
.jsp 파일을 서버에서 바로 접근할 수 없기 때문에 메서드를 두 개 호출한다
 - 
    
redirect할 jsp파일 명이 home.jsp일 경우 home만 작성한다
- 
        
@Controller public class MainController { @RequestMapping("method3") String m3() { return "redirect:/method4"; } @RequestMapping("method4") String m4() { return "home"; } } 
 - 
        
 - 
    
값을 전달하고 싶을 때
HttpSession,HttpServletRequest,Model등을 필요한 것들을 추가하여 사용할 수 있다 (여러개도 추가 가능) - 
    
Product라는 모델 클래스가 있을 경우 전달 받아 전송할 수 있다- 
        
이 메서드를 호출하는 곳에서 Product에 맞는 변수들을 넘겨준다면 자동으로 값이 넘어옴
 - 
        
클래스내의 변수명과 값을 받을 태그의 name명을 맞춰주어야 한다
 - 
        
public class Product { String pid; String pname; int pprice; String pdesc; } - 
        
<form action="result" method="post"> 아이디 : <input type="text" name="pid"><br> 상품명 : <input type="text" name="pname"><br> 가격 : <input type="number" name="pprice"><br> 설명 : <input type="text" name="pdesc"><br> <button>제출</button> </form> - 
        
@Controller public class MainController { @RequestMapping("method5") String m5(Product product, HttpStssion session, HttpServletRequest request, Model model) { session.setAttribute("product", product); request.setAttribute("product", product); model.addAttribute("product", product); return "page"; } } - 
        
전달 받은 값은 el태그 표현을 통해 받아올 수 있다
 - 
        
<%-- page.jsp --%> 전달 product : ${product} <br> 
 - 
        
 
프로젝트 진행시 필요한 것들
한글 인코딩 (web.xml에 추가)
<!-- 한글 파라미터 처리 -->
<filter>
  <filter-name>encoding</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
  </init-param>
</filter>
jdbc 연결 (pom.xml에 추가)
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.13</version>
</dependency>