ํ์ฌ ๊ธฐ๋ณธ ํ์ด์ง๋

index.jsp์ด๋ค.
์ด๋ฆ ๋ณ๊ฒฝ์ผ๋ก main.jsp๋ก ๋ณ๊ฒฝํจ
board์ main.jsp์๋ ๋ณ๊ฐ์

HomeController


package com.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MainController {
@GetMapping("/main")
public String main() {
return "/main";
}
}
ํ ์คํธํ๊ธฐ

๋ชจ๋ ์์ฒญ์ ์ปจํธ๋กค๋ฌ๋ก ๋ฐ์์ผํ๋ฏ๋ก
MainController ์์ฑํด์ ๋ฉ์ธ์ผ๋ก ๋ณด๋ด์ค์ผํจ
์์ ๋ฉ๋ด๊ฐ ์๋ธ
์ธํฐ์ ํฐ ์ค์ ์์ ์ด ํ์ํจ
<!--์ธํฐ์
ํฐ ์ค์ -->
<interceptors>
<interceptor>
<mapping path="/main" />
<mapping path="/board/*" />
<mapping path="/user/*" />
<beans:ref bean="MenuInterceptor" />
</interceptor>

MainService ์์ฑ

package com.demo.service;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo.dao.BoardDAO;
import com.demo.domain.ContentVO;
@Service
public class MainService {
@Autowired
private BoardDAO boardDAO;
// ๊ฐ ๋ฉ๋ด๋ณ๋ก ์ต๊ทผ ๊ฒ์๊ธ 5๊ฐ ๊ฐ์ ธ์ค๊ธฐ
public List<ContentVO> getMainList(int info_idx){
RowBounds rowBounds = new RowBounds(0,5);
return boardDAO.getContentList(info_idx, rowBounds);
}
}
MainController
package com.demo.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.demo.domain.ContentVO;
import com.demo.service.MainService;
@Controller
public class MainController {
@Autowired
private MainService mainService;
@GetMapping("/main")
public String main(Model model) {
ArrayList<List<ContentVO>> list = new ArrayList<List<ContentVO>>();
list.add(mainService.getMainList(1)); //1๋ฒ ๊ฒ์ํ (์์ ๊ฒ์ํ)
list.add(mainService.getMainList(2)); //2๋ฒ ๊ฒ์ํ (์ ๋ฉฐ๊ฒ์ํ)
list.add(mainService.getMainList(3)); //3๋ฒ ๊ฒ์ํ (์ ์น๊ฒ์ํ)
list.add(mainService.getMainList(4)); //4๋ฒ ๊ฒ์ํ (์คํฌ์ธ ๊ฒ์ํ)
model.addAttribute("list", list);
return "/main";
}
}
๋ฆฌ์คํธ๊ฐ ๋ง๋ค๋ฉด ๋ฐ๋ณต๋ฌธ ์ฌ์ฉ๊ฐ๋ฅํจ
main.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">์์ ๊ฒ์ํ</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>
<tr>
<td class="text-center">5</td>
<th><a href="${root}/board/read">์ ๋ชฉ์
๋๋ค</a></th>
<td class="text-center d-none d-xl-table-cell">2018-12-12</td>
</tr>
<tr>
<td class="text-center">5</td>
<th><a href="board_read.html">์ ๋ชฉ์
๋๋ค</a></th>
<td class="text-center d-none d-xl-table-cell">2018-12-12</td>
</tr>
<tr>
<td class="text-center">5</td>
<th><a href="board_read.html">์ ๋ชฉ์
๋๋ค</a></th>
<td class="text-center d-none d-xl-table-cell">2018-12-12</td>
</tr>
<tr>
<td class="text-center">5</td>
<th><a href="board_read.html">์ ๋ชฉ์
๋๋ค</a></th>
<td class="text-center d-none d-xl-table-cell">2018-12-12</td>
</tr>
<tr>
<td class="text-center">5</td>
<th><a href="board_read.html">์ ๋ชฉ์
๋๋ค</a></th>
<td class="text-center d-none d-xl-table-cell">2018-12-12</td>
</tr>
</tbody>
</table>
<a href="${root}/board/main" class="btn btn-primary">๋๋ณด๊ธฐ</a>
</div>
</div>
</div>
</c:forEach>โ
ํ ์คํธํ๊ธฐ (์์ ๊ฒ์ํ 4๊ฐ ์ถ๋ ฅ)

๋ฉ๋ด ์ ๋ชฉ ๋ณ๊ฒฝ
<h4 class="card-title">${topMenuList[idx.index].board_name}</h4>

๊ทธ๋ฆฌ๊ณ <tbody> ์์ <tr>ํ๋๋ง ๋จ๊ฒจ๋๊ณ ๋ค ์ญ์
<tr>ํ๋๋ฅผ ๋ฐ๋ณต๋ฌธ์ผ๋ก ๋ฐ๊ฟ

<tr>
<td class="text-center">${obj.board_idx}</td>
<th><a href="${root}/board/read?info_idx=${topMenuList[idx.index].info_idx}&board_idx=${obj.board_idx}">${obj.title}</a></th>
<td class="text-center d-none d-xl-table-cell">${obj.regDate}</td>
</tr>
</c:forEach>
</tbody>
</table>
<a href="${root}/board/main?info_idx=${topMenuList[idx.index].info_idx}" class="btn btn-primary">๋๋ณด๊ธฐ</a>
ํ ์คํธํ๊ธฐ

ํ ์คํธํ๊ธฐ
1. ๋ฉ์ดํ์ด์ง์ ๋๋ณด๊ธฐ ํด๋ฆญ


2. ๋ฉ์ดํ์ด์ง์ ๊ธ ํด๋ฆญ


'BACKEND > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ๊ฒ์ํ ๋ง๋ค๊ธฐ 2 - ํ์ด์ง ๋ค์ด์ ๊ตฌํ (0) | 2023.11.03 |
|---|---|
| ๊ฒ์ํ ๋ง๋ค๊ธฐ 2 - ๊ฒ์๊ธ ์ญ์ ์ฒ๋ฆฌ (1) | 2023.11.03 |
| ๊ฒ์ํ ๋ง๋ค๊ธฐ 2 - ๊ฒ์๊ธ ์์ ์ฒ๋ฆฌ (0) | 2023.11.02 |
| ๊ฒ์ํ ๋ง๋ค๊ธฐ 2 - ์ด๋ฏธ์ง ์ ๋ก๋ ๋ฐฉ๋ฒ ๋ณ๊ฒฝ (0) | 2023.11.02 |
| ๊ฒ์ํ ๋ง๋ค๊ธฐ 2 - ๊ฒ์๊ธ์ ๊ธ์ด์ด๋ง ์์ ๊ฐ๋ฅํ๊ฒ (0) | 2023.11.02 |