JSP - Maven - Board (Show all)

화이티 ·2023년 12월 21일
0

JSP

목록 보기
3/12

Main

<!-- Q17. 게시글 목록 조회 기능 -->
			<!-- Q18. 게시글 목록 세부페이지 기능(제목을 클릭하면 세부페이지 BoardDetail.jsp로 이동)-->
			<div id="board">
				<table id = "list">
					<tr>
						<td>번호</td>
						<td>제목</td>
						<td>작성자</td>
						<td>시간</td>
					</tr>
					<%
					List<Board> board  =new BoardDAO().allBoard();
					System.out.print(board.size());
						pageContext.setAttribute("board" , board);
						
				%>											<!-- s: 상태변수  -->
				<c:forEach var="b" items = "${board}" varStatus = "s">
				<tr>
						<td>${s.count}</td>
						<td><a href = "BoardDetail.jsp?num=${b.num}">${b.title}</a></td>
						<td>${b.writer }</td>
						<td>${b.b_date}</td>
					</tr>
				</c:forEach>

Board

package com.smhrd.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@AllArgsConstructor
@NoArgsConstructor
@RequiredArgsConstructor
@Getter
@ToString

public class Board {

	private int num;// index
	@NonNull
	private String title; // title
	@NonNull
	private String writer;
	@NonNull
	private String filename;
	@NonNull
	private String content;
	private String b_date;// upload time

}

BoardDAO

public List<Board> allBoard() {
		
	List<Board> board =null;
		try { 
			board = sqlSession.selectList("com.smhrd.database.BoardMapper.allBoard");
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
	return board;
	}

Board Mapper

<select id = "allBoard" resultType= "Board">
select * from  web_board1

</select>
profile
열심히 공부합시다! The best is yet to come! 💜

0개의 댓글