BoardDAO
public int p_new_count(String id) throws Exception; //사진첩 뉴 개수
public int p_count(String id) throws Exception; //사진첩 총 개수
public int b_new_count(String id) throws Exception; //게시판 뉴 개수
public int b_count(String id) throws Exception; //게시판 총 개수
public int v_new_count(String id) throws Exception; // 방명록 뉴 개수
public int v_count(String id) throws Exception; //방명록 총 개수
BoardDAOImpl
// 게시판별 게시물 수
@Override
public int p_new_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".p_new_count", id);
}
@Override
public int p_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".p_count", id);
}
@Override
public int b_new_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".b_new_count", id);
}
@Override
public int b_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".b_count", id);
}
@Override
public int v_new_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".v_new_count", id);
}
@Override
public int v_count(String id) throws Exception {
return sqlSession.selectOne(namespace+".v_count", id);
}
BoardService
public int p_new_count(String id) throws Exception; //사진첩 뉴 개수
public int p_count(String id) throws Exception; //사진첩 총 개수
public int b_new_count(String id) throws Exception; //게시판 뉴 개수
public int b_count(String id) throws Exception; //게시판 총 개수
public int v_new_count(String id) throws Exception; // 방명록 뉴 개수
public int v_count(String id) throws Exception; //방명록 총 개수
BoardServiceImpl
@Override
public int p_new_count(String id) throws Exception {
return dao.p_new_count(id);
}
@Override
public int p_count(String id) throws Exception {
return dao.p_count(id);
}
@Override
public int b_new_count(String id) throws Exception {
return dao.b_new_count(id);
}
@Override
public int b_count(String id) throws Exception {
return dao.b_count(id);
}
@Override
public int v_new_count(String id) throws Exception {
return dao.v_new_count(id);
}
@Override
public int v_count(String id) throws Exception {
return dao.v_count(id);
}
BoardMapper
<!-- main 게시물 수 -->
<select id="p_new_count" resultType="int">
select count(*) from board where id=#{id} and tab='p' and (DATE(regdate) >= DATE_SUB(now(),INTERVAL 1 DAY))
</select>
<select id="p_count" resultType="int">
select count(*) from board where id=#{id} and tab='p'
</select>
<select id="b_new_count" resultType="int">
select count(*) from board where id=#{id} and tab='b' and (DATE(regdate) >= DATE_SUB(now(),INTERVAL 1 DAY))
</select>
<select id="b_count" resultType="int">
select count(*) from board where id=#{id} and tab='b'
</select>
<select id="v_new_count" resultType="int">
select count(*) from board where id=#{id} and tab='v' and (DATE(regdate) >= DATE_SUB(now(),INTERVAL 1 DAY))
</select>
<select id="v_count" resultType="int">
select count(*) from board where id=#{id} and tab='v'
</select>
BoardController
@GetMapping("/main")
public void mainGET( Model model, BoardVO b) throws Exception {
//logger.info("main start====");
// main 각 게시판의 게시물 수
int p_new_count = service.p_new_count(b.getId()); //new 개수
int p_count = service.p_count(b.getId()); //총 개수
int b_new_count = service.b_new_count(b.getId()); //new 개수
int b_count = service.b_count(b.getId()); //총 개수
int v_new_count = service.v_new_count(b.getId()); //new 개수
int v_count = service.v_count(b.getId()); //총 개수
model.addAttribute("p_new_count", p_new_count);
model.addAttribute("p_count", p_count);
model.addAttribute("b_new_count", b_new_count);
model.addAttribute("b_count", b_count);
model.addAttribute("v_new_count", v_new_count);
model.addAttribute("v_count", v_count);
}
main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/views/include/header_board.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>미니홈피</title>
<style>
.b_total { /* 테이블 */
/* border:1px solid blue; */
width:325px;
}
hr {
margin:3px 0px;
height:2px;
background-color: #ccc;
border:none;
}
.table {
display: table;
width:100%;
border:1px solid #ccc;
table-layout: fixed;
}
.row {
display: table-row;
border:1px solid #ccc;
}
.cell {
display: table-cell;
border:1px solid #ccc;
height:20px;
font-size: 13px;
text-align: center;
}
.new {
background-color: #f15E3D;
color:#fff;
font-size:5px;
font-weight: bolder;
padding:0px 2px;
border-radius:2px;
}
</style>
<div class="b_total">
<div class="table">
<div class="row">
<div class="cell">
<a href="/board/list?id=${id}&tab=p">사진첩</a>
<c:if test="${p_new_count != 0}">
<span class="new">N</span>
</c:if>
<span style="color:#f15E3D">${p_new_count }</span>
<span>/ ${p_count }</span>
</div>
<div class="cell">
<a href="/board/list?id=${id}&tab=b">게시판</a>
<c:if test="${b_new_count != 0}">
<span class="new">N</span>
</c:if>
<span style="color:#f15E3D">${b_new_count }</span>
<span>/ ${b_count }</span>
</div>
</div>
<div class="row">
<div class="cell">
<a href="/board/list?id=${id}&tab=v">방명록</a>
<c:if test="${v_new_count != 0}">
<span class="new">N</span>
</c:if>
<span style="color:#f15E3D">${v_new_count }</span>
<span>/ ${v_count }</span>
</div>
<div class="cell"> </div>
</div>
<div class="row">
<div class="cell"> </div>
<div class="cell"> </div>
</div>
</div>
</div>
<%@include file="/WEB-INF/views/include/footer_board.jsp" %>
'프로젝트 로직 모음집 > spring' 카테고리의 다른 글
Today is 기분선택 (0) | 2023.06.03 |
---|---|
최신글4개list (0) | 2023.06.03 |
선택삭제 (0) | 2023.06.02 |