Spring/Spring MVC2 5

Board - 게시물 등록 및 수정 / 첨부 파일 인코딩 및 등록

게시글 등록 write.jsp 게시판 작성 제목 작성자 첨부파일 내용 servlet-context.xml 로그인 하지 않은 사람은 url로접근하지 못하도록 인터셉터에 매핑한다. BoardController @GetMapping("/write") public String write() { log.info("게시글 작성 페이지 요청"); return "board/write"; } jsp 페이지가 연결되도록 Controller 에서 get 요청을 한다. 클래스 상단에 @RequestMapping("/board") 설정하면 mapping 할 때 자동으로 앞에 "/board"를 표시해준다. 추가로, post 요청을 처리하는 메소드를 만든다. (GetMapping만 하면 405 에러 발생) pom.xml commo..

Spring/Spring MVC2 2022.10.24

Board - 전체 게시글 / 상세 페이지 / 게시글 삭제

@controller 등록 controller로 등록하기 위해 @controller 어노테이션을 BoardController 클래스 상단에 추가 @controller - 웹 애플리케이션에서 웹 요청과 응답을 처리하는 빈을 생성한다. Bean을 찾아 자동으로 맵핑시켜주기 위해 @Autowired 어노테이션을 BoardService 메서드 상단에 추가 게시글 전체 리스트 @GetMapping("/board/list") public ModelAndView list(ModelAndView model, @RequestParam(value="page", defaultValue="1") int page) { List list = null; PageInfo pageInfo = null; pageInfo = new Pa..

Spring/Spring MVC2 2022.10.23

기본 설정 ② root-context.xml

root-context.xml @PropertySource()을 생략하여 driver.properties 연결 db.driver=oracle.jdbc.driver.OracleDriver db.url=jdbc:oracle:thin:@localhost:1521:xe db.username=WEB db.password=WEB 요소를 사용하여 다른 XML 설정 연결 import 요소를 사용해 xml 연결할 수 있어 여러 개 설정이 가능하다. mybatis-context.xml mybatis-config.xml에 있는 속성들을 bean으로 등록하는 방법을 사용하기 BasicDataSource Configuration 빈의 속성을 직접 적용 p:mapperLocations="classpath:mappers/**/*...

Spring/Spring MVC2 2022.09.02

기본 설정 ① web.xml

web.xml context-param contextConfigLocation /WEB-INF/spring/root-context.xml 실제 애플리케이션을 구동할 때 실행되는 xml 설정(/WEB-INF/spring/root-context.xml) ContextLoaderListener에서 Root WebApplicationContext를 생성하기 위한 설정 파일의 경로 지정 listener - ContextLoaderListener org.springframework.web.context.ContextLoaderListener ContextLoaderListener 웹 애플리케이션의 시작, 종료 이벤트에 대한 이벤트 리스너이다. 웹 애플리케이션 구동 시 루트 애플리케이션 컨텍스트를 생성하고 웹 애플리..

Spring/Spring MVC2 2022.09.02