본문 바로가기

BACK

[SpringBoot JSP] 게시판목록을 메인화면에연결

728x90

1. Controller (indexController.java)

@RequestMapping(path = {""})
public ModelAndView index(Principal principal, @RequestParam(value = "logout", defaultValue = "false") Boolean logout) {

    //문의하기
    /*page:1 -> page가 1페이지인것 출력, page:2 -> page가 2페이지인것*/
    List<Content> contents = noticeService.appearNoticeInfo(2);

    //리뷰하기
    PageInfo pageInfo = new PageInfo(1, 7);
    pageInfo.setItemCountTatal(noticeRepository.getPageCountReview());

    List<Reviews> reviews = noticeService.appearNoticeReviewsInfo(pageInfo);

    return new ModelAndView("index")
            .addObject("contents",contents)
            .addObject("reviews",reviews);

}

 

2. view (index.jsp)

<div class="column is-6">
    <div class="category">
        <h1 class="title is-5">
             <a href='questions'>문의하기</a>
        </h1>
        <hr />

        <ul>
            <c:forEach var='obj' items="${contents }">
                <li>
                    <a href='questions-write-form?contentIdx=${obj.contentIdx}'>${obj.contentSubject }</a>
                </li>
            </c:forEach>
        </ul>

        <h3 class="category-more">View All <i class="far fa-arrow-right icon-padding-left"></i></h3>
    </div>
</div>

<div class="column is-6">
    <div class="category">
        <h1 class="title is-5">
            <a href='review'>리뷰</a>
        </h1>
        <hr />

        <ul>
            <c:forEach var='obj' items="${reviews }">
                <li>
                    <a href='review-write-form?reviewsIdx=${obj.reviewsIdx}'>${obj.reviewsSubject }</a>
                </li>
            </c:forEach>
        </ul>
	</div>
</div>

 

--------------

만약,href에 page번호도 추가하고 싶다면 전체적으로 다 바꿔야한다.

주소는 같게 연결되어있어야하기 때문이다.

728x90