[Spring] 10. 게시판 리스트개발자가 되기까지 (2023.08.16~2024.04.15)/[Spring] Basic Web2024. 1. 16. 23:39
Table of Contents
list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:include page="../layout/header.jsp"></jsp:include>
<jsp:include page="../layout/nav.jsp"></jsp:include>
<div class="container-md">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">제목</th>
<th scope="col">작성자</th>
<th scope="col">조회수</th>
<th scope="col">댓글</th>
<th scope="col">등록일</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list }" var="bvo">
<tr>
<th scope="row">${bvo.bno}</th>
<td><a href="/board/detail?bno=${bvo.bno}">${bvo.title}</a></td>
<td>${bvo.writer}</td>
<td>${bvo.readCount}</td>
<td>${bvo.cmtQty}</td>
<td>${bvo.regAt}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<jsp:include page="../layout/footer.jsp"></jsp:include>
BoardController.java
package com.basicWeb.www.controller;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.basicWeb.www.domain.BoardVO;
import com.basicWeb.www.service.BoardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequestMapping("/board/*")
@RequiredArgsConstructor
@Controller
public class BoardController {
private final BoardService bsv;
// ... (기존 코드)
@GetMapping("/list")
public void list (Model m) {
List<BoardVO> list = bsv.getList();
m.addAttribute("list", list);
}
}
BoardService.interface
package com.basicWeb.www.service;
import java.util.List;
import com.basicWeb.www.domain.BoardVO;
public interface BoardService {
void register(BoardVO bvo);
List<BoardVO> getList();
}
BoardServiceImpl.java
package com.basicWeb.www.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.basicWeb.www.domain.BoardVO;
import com.basicWeb.www.repository.BoardDAO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor
@Service
public class BoardServiceImpl implements BoardService{
private final BoardDAO bdao;
// ... (기존 코드)
@Override
public List<BoardVO> getList() {
return bdao.getList();
}
}
BoardDAO.interface
package com.basicWeb.www.repository;
import java.util.List;
import com.basicWeb.www.domain.BoardVO;
public interface BoardDAO {
void register(BoardVO bvo);
List<BoardVO> getList();
}
boardMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.basicWeb.www.repository.BoardDAO">
<insert id="register">
INSERT INTO board title, writer, content)
VALUES (#{title}, #{writer}, #{content})
</insert>
<select id="getList" resultType="com.basicWeb.www.domain.BoardVO">
SELECT * FROM board ORDER BY bno desc
</select>
</mapper>
<게시판 리스트 화면>
[Spring] 10. 게시판 리스트
(다음 게시물 예고편)
[Spring] 11. 게시물 상세 / 수정 / 삭제
728x90
@rlozlr :: 얼렁뚱땅 개발자
얼렁뚱땅 주니어 개발자
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!