Configuration
-
Configuration File 설정Spring-diary/WEB 2020. 2. 12. 10:04
Configuratin File을 다수 설정할 수 있다. 환경설정 하는 Configuration 파일 하나와 Controller를 설정하는 파일 하나로 조정할 수 있다. Web.xml Configuration 파일 위치 설정 Web.xml에서 Configuration 파일의 위치를 설정해 줄때 두개로 잡아준다. Web.xml에 설정한 경로와 이름대로 파일을 만들어준다. namespace MVC이용해 resolver 설정 namespace 설정 Tag 설정 context:component-scan Controller 사용시 일일이 Bean으로 등록해 사용하는 불편함을 줄이는 context:component-scan을 사용한다. 패키지에 있는 controller를 찾아서 자동으로 등록해준다. 대신에 Anno..
-
Controller에 Autowired 사용하기Spring-diary/WEB 2020. 2. 11. 17:44
Controller에도 멤버 필드에 Autowired를 사용할 수 있다. DB에 접속하는 Controller를 만드는 경우 DB 공통 Interface를 만든 후 Bean을 이용해 DB의 종류를 바꿔가며 사용할 수 있다. ex) Mysql 사용하기 Interface 생성 Mysql에서 특정 DB에 table 생성 MysqlDAO class에 CommonDAO Interface 연결 DB연결 metho와 어느 DB에 연결할지 명령어 입력 Dispatcher에 bean 생성 Controller Method *url에 어느 db에 접속할지 미리 명시해 줘도 된다. jdbc:mysql://localhost:3306/접속할db이름?serverTimezone=UTC# package에 있는 모든 Controller를..