-
[SPRING] SPRING 게시판 (4) - CRUD [게시물 리스트]JAVA/SPRING 2020. 3. 12. 20:43728x90
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'JAVA > SPRING' 카테고리의 다른 글
[SPRING] SPRING 게시판 (6) - CRUD [게시물 상세보기] (0) 2020.03.16 [SPRING] SPRING 게시판 (5) - CRUD [게시물 작성] (0) 2020.03.14 [SPRING] SPRING 게시판 (3) - DB 연동2 (0) 2020.03.11 [SPRING] Resource specification not allowed here for source level below 1.7 Error (0) 2020.03.11 [SPRING] SPRING게시판 (2) - DB 연동 (0) 2020.03.10