IOC(Inversion of Control) - 제어의 역전
DI(Dependency injection) - 의존 관계 객체 자동
DL(Dependency Lookup)
##DI(Dependency injection)
1,xml
2,anotaion
3,configuration java class
##xml
<이전>
ex)
Book dto 1 = new Magazine();
dto.setXXX(XXX);
Book dto 1 = new Magazine();
//다형성
Book magazine = new Magazine("a","b");
Book comicbook = new ComicBook("a","b");
BookDao dao = BookDaoImpl.getInstance();
request.setAttribute(K,V);
session.setAttribute(K,V);
<beans>
<!--기본 생성자 인젝션 -->
<bean id = " " class =" " scope="singleton | prototype | request"/> //자식이 없을 때
<!-- 파라메터 전달 생성자 인젝션: 선언한 순서대로 값 전달, index=전달순서지정 -->
<bean id=" " class " "> //자식이 있을 때
<constructor-arg value="data" [index="0"]/>
<constructor-arg ref="객체(bean id)" [index="0"]/>
</bean>
<bean id=" " class = " ">
<property name = "멤버변수명" value="data"/>
<property name = "멤버변수명" ref = " " />
</bean>
</beans>
##anotaion
--xsd : spring-context
--bean config.xml
<context:conponent-scan base-package="com.ssafy.ws, com.ssafy.model"/> 프로젝트 크기가 작을 때, 크면 여러개 올 수도 있다(, 구분)
<context:conponent-scan base-package="com.ssafy.ws, com.ssafy.model"></context.conponent-scan>
--back-package에 지정한 패키지에 있는 클래스들 중에서 빈 설정(어노테이션) 스캐닝
>>@Component : 사용자가 작성한 빈객체
>>@Autowired : @Component 빈 객체에서 의존관계 객체 자동 주입
##web MVC 객체 의존관계 흐름도
#spring lagacy project
src/main/java - 실제 동작
src/main/resourse - 부가적인 자원
src/test/java -단위테스트
src/test/resouce - 단위테스트 자원
src - main- webapp -webinf - web.xml : servlet container가 관리
#spring web mvc 환경설정
1.web.xml
--web application 관련 설정
2.root- context.xml
--웹 이외 관련 설정
--Model(DB) 관련 설정
3. servlet-context.xml
--웹 관련 설정
4.log4j.xml
--로깅 관리 설정
##logging 처리
--기존 개발시 디버그: => 개발 완료하면 모두 찾아서 지워야 함!!
system.out.println("aaaa);
--log4j 로깅 관리 오픈소스
>>spring 자동 포함 사용가능
>> 로그 환경설정:
>src/main/resourse> log4j.xml
>>로그 레벨 조정
<logger name="com.ssafy.ws">
<level value="info" />
</logger>
--로그 레벨
>>fatal : 심각
>>error : 오류
>>wran : 경고
>>info : 정보(권장)
>>debug : 개발시 디버깅 목적
-로그사용하기위한 클래스에 로거 객체 생성
// 현재 클래스에서 사용하기 위한 로그 객체 생성
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/로그 메세지 출력
logger.info("메세지");
logger.info("{},{} 메세지", agr1, arg2);
logger.debug("메세지");
logger.debug("{},{} 메세지", agr1, arg2);
## @Controller 응답 설정
--Model
>>응답 데이터 설정
--ModelAndView
>> 응답 데이터 + 응답 화면 설정
##@Controller 서비스메서드 반환타입
1,String
--응답 view 이름
--InternalResourceViewResolver
--model di 인젝션 받아서 설정
2, ModelAndView
--응답 위한 속성 및 응답 view 이름
3, void
--동일 요청페이지
##@Controller http method요청
@RequestMapping("url-pattern")
@RequestMapping("url-pattern", method =RequestMethod.GET)
@GetMapping(value={"url-pattern", "url-pattern-2"})
--http post 요청
@RequestMapping("url-pattern", method =RequestMethod.POST)
@PostMapping(value={"url-pattern-1", "url-pattern-2"})
## @Controller 서비스메서드 parm 데이터 가져오기
public String methodA(Member member);
public String methodA(String memberId, String memberPw, int age);
public String methodA(@RequestParam("id") String memberId, @RequestParam("id", required=false, defaultValue="guest") String memberPw, int age);
'Spring' 카테고리의 다른 글
[Spring]Mybatis- SqlSessionFactory (0) | 2022.10.25 |
---|---|
[Spring]Spring JDBC, DataSource (0) | 2022.10.25 |
[Spring]mybatis-spring (0) | 2022.10.25 |
[Spring]MVC (0) | 2022.10.21 |
[Spring]spring project (0) | 2022.10.21 |