티스토리 뷰
1. command 객체 수정
- BoardVO에 searchCondition과 searchKeyword 변수와 getter/setter 메소드를 추가한다.
2. controller 구현
- 로그인 성공 후의 상황이나 상세 화면에서 글 목록으로 되돌아올 경우 전체 목록 검색을 위해 null 체크를 한다.
- 기본이 TITLE에 Keyword는 "" 검색
1 2 3 4 5 6 7 8 9 10 11 12 13 | // 글 목록 검색 @RequestMapping("/getBoardList.do") public String getBoardList(BoardVO vo, Model model) { // System.out.println("글 목록 검색 처리"); if(vo.getSearchCondition() == null) { vo.setSearchCondition("TITLE"); } if(vo.getSearchKeyword() == null) { vo.setSearchKeyword(""); } model.addAttribute("boardList", boardService.getBoardList(vo)); // Model 정보 저장 return "getBoardList.jsp"; } | cs |
3. DAO 클래스 수정
3-1 BoardDAO 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | // ~~~~~ private final String BOARD_LIST_T = "select * from board where title like '%'||?||'%' order by seq desc"; private final String BOARD_LIST_C = "select * from board where content like '%'||?||'%' order by seq desc"; // ~~~~~ // 글 목록 조회 public List<BoardVO> getBoardList(BoardVO vo) { System.out.println("===> JDBC로 getBoardList() 기능 처리"); List<BoardVO> boardList = new ArrayList<BoardVO>(); try { conn = JDBCUtil.getConnection(); // stmt = conn.prepareStatement(BOARD_LIST); if(vo.getSearchCondition().equals("TITLE")) { stmt = conn.prepareStatement(BOARD_LIST_T); } else if(vo.getSearchCondition().equals("CONTENT")) { stmt = conn.prepareStatement(BOARD_LIST_C); } stmt.setString(1, vo.getSearchKeyword()); rs = stmt.executeQuery(); while (rs.next()) { BoardVO board = new BoardVO(); board.setSeq(rs.getInt("SEQ")); board.setTitle(rs.getString("TITLE")); board.setWriter(rs.getString("WRITER")); board.setContent(rs.getString("CONTENT")); board.setRegDate(rs.getDate("REGDATE")); board.setCnt(rs.getInt("CNT")); boardList.add(board); } } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtil.close(rs, stmt, conn); } return boardList; } | cs |
3-2. BoardDAOSpring 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // ~~~~~ private final String BOARD_LIST_T = "select * from board where title like '%'||?||'%' order by seq desc"; private final String BOARD_LIST_C = "select * from board where content like '%'||?||'%' order by seq desc"; // ~~~~~ // 글 목록 조회 public List<BoardVO> getBoardList(BoardVO vo) { System.out.println("===> JDBC로 getBoardList() 기능 처리"); Object[] args = {vo.getSearchKeyword()}; if(vo.getSearchCondition().equals("TITLE")) { return jdbcTemplate.query(BOARD_LIST_T, args, new BoardRowMapper()); } else if(vo.getSearchCondition().equals("CONTENT")) { return jdbcTemplate.query(BOARD_LIST_C, args, new BoardRowMapper()); } return null; } // ~~~~~ | cs |
'spring' 카테고리의 다른 글
| day4 class07 다국어 처리 (0) | 2019.02.16 |
|---|---|
| day4 class05 파일 업로드 및 예외 처리 (0) | 2019.02.12 |
| day4 class03 프레젠테이션 레이어와 비즈니스 레이어 통합 (0) | 2019.02.10 |
| day4 class02 어노테이션으로 게시판 프로그램 구현하기 (0) | 2019.02.09 |
| day4 class01 어노테이션 기반 MVC 개발 (0) | 2019.02.07 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- blocking
- Controller
- NoClassDefFoundError
- 검색
- XmlWebApplicationContext
- java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
- aop
- 의존성 주입
- JoinPoint
- setter 인젝션
- @Autowired
- 컨트롤러
- 스프링 컨테이너
- Class path contains multiple SLF4J bindings
- SqlSessionFactoryBean
- servlet context
- handlermapping
- preHandler
- postHandler
- 어노테이션
- application context
- 의존성
- ViewResolver
- LoggingEvent
- 횡단 관심
- multiple SLF4J bindings
- afterCompletion
- aspect oriented programming
- #java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent삭제
- exclude-mapping
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
글 보관함
