게시판 게시판 글목록 구현

JEONG SUJIN·2022년 12월 30일
0

기존에있던 내용은 html으로 넣은거라, 직접글을 많이 등록해야한다.

ContentBean.java

private String content_writer_name; //글쓴이 이름 추가

public String getContent_writer_name() {
		return content_writer_name;
	}

public void setContent_writer_name(String content_writer_name) {
		this.content_writer_name = content_writer_name;
	}
	

BoardMapper.java

@Select("select t1.content_idx, t1.content_subject, t2.user_name as content_writer_name, " + 
			"DATE_FORMAT(t1.content_date, '%Y.%m.%d') as content_date " + 
			"from content_table t1 JOIN user_table t2 " + 
			
			"ON t1.content_writer_idx = t2.user_idx " +
			"and t1.content_board_idx = #{board_info_idx} order by t1.content_idx desc")
	
	List<ContentBean> getContentList(int board_info_idx);
	

BoardService.java

//페이지에 해당하는 글들을 가져온다.
public List<ContentBean> getContentList(int board_info_idx){
		return boardMapper.getContentList(board_info_idx);
	}

BoardController.java

@GetMapping("/main")
	public String main(@RequestParam("board_info_idx") int board_info_idx, Model model,@RequestParam(value = "page", defaultValue = "1") int page)  {
		
		model.addAttribute("board_info_idx", board_info_idx);
		
		System.out.println("board_info_idx : 컨트롤러 @@@ " + board_info_idx);
		
		String boardInfoName = boardService.getBoardInfoName(board_info_idx);
		model.addAttribute("boardInfoName", boardInfoName);
		
		List<ContentBean> contentList = boardService.getContentList(board_info_idx );
		model.addAttribute("contentList", contentList);
		System.out.println("cotentList : " + contentList.toString());
		System.out.println("board_info_idx ::!!!!!" + board_info_idx);
		
		return "board/main";
		
	}

main.jsp

 <c:forEach var="obj" items="${contentList}">
              <tr>
                <td class="text-center d-none d-md-table-cell">${obj.content_idx }</td>
                 <td><a href="${root }board/main">${obj.content_subject }</a></td>
                

                 <td class="text-center d-none d-md-table-cell">${obj.content_writer_name }</td>
                <td class="text-center d-none d-md-table-cell">${obj.content_date }</td>
              </tr>
</c:forEach>  

리스트에 출력이 잘 되는걸 볼 수 있다.

profile
기록하기

0개의 댓글