게시판 메인페이지

JEONG SUJIN·2022년 12월 30일
0

각 게시판 별로 최근 글5개를 가져와서 화면 표시하기

MainService.java

mapper는 이미 board_table에서 글들을 가져오는 메서드를 사용

@Service
public class MainService {

	@Autowired
	private BoardMapper boardMapper;
	
	public List<ContentBean> getMainList(int board_info_idx){
		RowBounds rowBounds = new RowBounds(0,5);
		return boardMapper.getContentList(board_info_idx,rowBounds);
	}
}

MainController.java

@Controller
public class MainController {
    
	@Autowired
	private MainService mainService;
	
	@GetMapping("/main")
	public String main(Model model) {
		ArrayList<List<ContentBean>> list = new ArrayList<List<ContentBean>>();
		
		list.add(mainService.getMainList(1));
		list.add(mainService.getMainList(2));

		
		model.addAttribute("list", list);
		
		return "main";
	}
}

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var='root' value="${pageContext.request.contextPath }/" />

<!-- 상단 부분  -->
<c:import url="/WEB-INF/views/include/menu.jsp" />
<!-- 게시판 미리보기 부분 -->
<div class="container" style="margin-top: 100px">
	<div class="row">
 <c:forEach var="sub_list" items="${list}" varStatus="idx">     
 
		<div class="col-lg-6" style="margin-top: 20px">
			<div class="card shadow">
				<div class="card-body">
					<h4 class="card-title">${topMenuList[idx.index].board_info_name}</h4>
					
					<table class="table table-hover" id="board_list">
						<thead>
							<tr>
								<th class="text-center w-25">글번호</th>
								<th>제목</th>
								<th class="text-center w-25 d-none d-xl-table-cell">작성날짜</th>
							</tr>
						</thead>
					


						<tbody>
							<c:forEach var="obj" items="${sub_list}">
								<tr>
									<td class="text-center">${obj.content_idx }</td>
									<th><a
										href="${root }/board/read?board_info_idx=${topMenuList[idx.index].board_info_idx}&content_idx=${obj.content_idx}&page=1">${obj.content_subject }</a></th>
									<td class="text-center d-none d-xl-table-cell">${obj.content_date }</td>
								</tr>
							</c:forEach>
						</tbody>


					</table>
				

					<a href="${root }board/main" class="btn btn-primary">더보기</a>
				</div>
			</div>
		</div>
</c:forEach>


	</div>
</div>
<!-- 푸터부분  -->
<c:import url="/WEB-INF/views/include/footer.jsp" />

profile
기록하기

0개의 댓글