JAVA/SPRING
[SPRING] SPRING 게시판 (4) - CRUD [게시물 리스트]
KMSEOP
2020. 3. 12. 20:43
728x90
Service 생성
// Service/BoardService.java
@Service
public class BoardService {
@Inject
private BoardDao boardDao;
public List<BoardVo> getBoardList() throws Exception{
return boardDao.getBoardList();
}
}
Controller 생성
// Controller/BoardController.java
@Controller
public class BoardController {
@Inject
private BoardService boardService;
@RequestMapping(value="/boardList", method=RequestMethod.GET)
public ModelAndView boardList() throws Exception{
ModelAndView model = new ModelAndView();
model.setViewName("index");
List<BoardVo> boardList = boardService.getBoardList();
model.addObject("boardList", boardList);
return model;
}
}
View 생성
// webapp/WEB-INF/views/index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style>
#list{
border: 1px solid black;
}
th, td {
border: 1px solid #444444;
}
</style>
</head>
<body>
<table id="list">
<thead>
<tr>
<th>NO</th>
<th>TITLE</th>
<th>WRITER</th>
<th>COUNT</th>
<th>DATE</th>
</tr>
</thead>
<tbody>
<c:forEach var="item" items="${boardList}">
<tr>
<td>${item.bno}</td>
<td>${item.title}</td>
<td>${item.writer}</td>
<td>${item.count}</td>
<td>${item.createTime}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
728x90