필드명 : 글번호, 작성자, 작성일자, 제목, 내용,
readcnt(조회수), groups(그룹),step(내려쓰기),indent(들여쓰기)
글번호 : 자동생성 sequence 사용
작성일자 : 자동기입 sysdata
컬럼별 설명
groups : 댓글(답글)의 경우 원본글에서 파생된 글이기에
원본글과의 값이 같다. (정렬을 위한)
step : 그룹안에서의 댓글 순서.
(그룹원본글에서 바로 아래 즉 가까운 댓글이 값이 낮음 (대댓글포함))
새댓글이 계속 달릴수록
그룹안에 새댓글 위치의 아래 댓글들의 step 값이 다같이 올라감
indent : 댓글(답글)의 가독성을 위한 들여쓰기값
ex) Re: , 공백
=> groups 내림차순 정렬 후에 step 오름차순 정렬
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value=""/>
<put-attribute name="top" value="/WEB-INF/views/top.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
<definition name="main" extends="baseLayout">
<put-attribute name="title" value="메인화면"/>
<put-attribute name="body" value="/WEB-INF/views/main.jsp"/>
</definition>
<definition name="boardinput" extends="baseLayout">
<put-attribute name="title" value="게시판입력"/>
<put-attribute name="body" value="/WEB-INF/views/board/boardinput.jsp"/>
</definition>
<definition name="boardoutput" extends="baseLayout">
<put-attribute name="title" value="게시판출력"/>
<put-attribute name="body" value="/WEB-INF/views/board/boardoutput.jsp"/>
</definition>
<definition name="boarddetail" extends="baseLayout">
<put-attribute name="title" value="게시판내용"/>
<put-attribute name="body" value="/WEB-INF/views/board/boarddetail.jsp"/>
</definition>
<definition name="reply" extends="baseLayout">
<put-attribute name="title" value="게시판댓글"/>
<put-attribute name="body" value="/WEB-INF/views/board/reply.jsp"/>
</definition>
</tiles-definitions>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">게시판 입력</h3>
<form action="boardsave" method="post">
<table border="1" align="center">
<tr>
<th>작성자</th>
<td><input type="text" name="writer"></td>
</tr>
<tr>
<th>제목</th>
<td><input type="text" name="title"></td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea rows="10" cols="30" name="content"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="글등록">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">게시판 출력</h3>
<table border="1" align="center" width="800px">
<tr>
<th>번호</th><th>작성자</th><th>제목</th><th>작성일자</th><th>조회수</th>
<th>그룹</th><th>스탭</th><th>들여쓰기</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td>
<a href="delete?num=${list.num}">${list.num}</a>
</td>
<td>${list.writer}</td>
<td>
<a href="detail?num=${list.num}">
<c:if test="${list.indent >= 1}">
<c:forEach var="i" begin="1" end="${list.indent}"> </c:forEach>
</c:if>
${list.title}</a>
</td>
<td>${list.writeday}</td><td>${list.readcnt}</td>
<td>${list.groups}</td><td>${list.step}</td><td>${list.indent}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">자세히 보기</h3>
<form action="reply" method="post">
<table border="1" align="center">
<input type="hidden" name="num" value="${dto.num}">
<tr>
<th>제목</th>
<td>${dto.title}</td>
</tr>
<tr>
<th>작성자</th>
<td>${dto.writer}</td>
</tr>
<tr>
<th>조회수</th>
<td>${dto.readcnt}</td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea rows="10" cols="30">${dto.content}</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="댓글달기">
<input type="button" value="메인" onclick="location.href='main'">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">게시판 댓글입력</h3>
<form action="replysave" method="post">
<input type="hidden" name="num" value="${dto.num}">
<input type="hidden" name="groups" value="${dto.groups}">
<input type="hidden" name="step" value="${dto.step}">
<input type="hidden" name="indent" value="${dto.indent}">
<table border="1" align="center">
<tr>
<th>작성자</th>
<td><input type="text" name="writer"></td>
</tr>
<tr>
<th>제목</th>
<td><input type="text" name="title"></td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea rows="10" cols="30" name="content"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="글등록">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
package com.ezen.kim15_001.board;
public class BoardDTO {
int num;
String writer,title,content,writeday;
int readcnt,groups,step,indent;
public BoardDTO() {
}
public BoardDTO(int num, String writer, String title, String content, String writeday, int readcnt, int groups,
int step, int indent) {
super();
this.num = num;
this.writer = writer;
this.title = title;
this.content = content;
this.writeday = writeday;
this.readcnt = readcnt;
this.groups = groups;
this.step = step;
this.indent = indent;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getWriteday() {
return writeday;
}
public void setWriteday(String writeday) {
this.writeday = writeday;
}
public int getReadcnt() {
return readcnt;
}
public void setReadcnt(int readcnt) {
this.readcnt = readcnt;
}
public int getGroups() {
return groups;
}
public void setGroups(int groups) {
this.groups = groups;
}
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public int getIndent() {
return indent;
}
public void setIndent(int indent) {
this.indent = indent;
}
}
package com.ezen.kim15_001.board;
import java.util.ArrayList;
public interface Service1 {
public void boardinsert(String writer,String title,String content);
public ArrayList<BoardDTO> boardout();
public BoardDTO boarddetail(int num);
public void boardnumcnt(int num);
public void delete(int num);
public BoardDTO reply(int num);
public void replyinsert(int num,String writer,String title,String content,int groups,int step,int indent);
public void stepup(int groups,int step);
}
<?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.ezen.kim15_001.board.Service1">
<insert id="boardinsert">
insert into board (num,writer,title,content,groups)
values (num_seq.nextval,#{param1},#{param2},#{param3},num_seq.currval)
</insert>
<select id="boardout" resultType="com.ezen.kim15_001.board.BoardDTO">
select num,writer,title,to_char(writeday,'yyyy-MM-dd') as writeday,readcnt,indent,groups,step from board
order by groups desc,step asc
</select>
<update id="boardnumcnt">
update board set readcnt=readcnt+1 where num = #{param1}
</update>
<select id="boarddetail" resultType="com.ezen.kim15_001.board.BoardDTO">
select num,writer,title,to_char(writeday,'yyyy-MM-dd') as writeday,readcnt,content from board
where num = #{param1}
order by groups desc,step asc
</select>
<delete id="delete">
delete from board where num = #{param1}
</delete>
<select id="reply" resultType="com.ezen.kim15_001.board.BoardDTO">
select * from board where num = #{param1}
</select>
<insert id="replyinsert">
insert into board (num,writer,title,content,groups,step,indent)
values (num_seq.nextval,#{param2},#{param3},#{param4},#{param5},#{param6},#{param7})
</insert>
<update id="stepup">
<![CDATA[
update board set step=step+1 where groups = #{param1} and step > #{param2}
]]>
</update>
</mapper>
package com.ezen.kim15_001.board;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BoardController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/boardinput")
public String ko1() {
return "boardinput";
}
@RequestMapping(value="/boardsave")
public String ko2(HttpServletRequest request) {
String writer = request.getParameter("writer");
String title = request.getParameter("title");
String content = request.getParameter("content");
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.boardinsert(writer, title, content);
return "redirect:boardinput";
}
@RequestMapping(value="/boardout")
public String ko3(Model mo) {
Service1 ss1 = sqlsession.getMapper(Service1.class);
ArrayList<BoardDTO> list = ss1.boardout();
mo.addAttribute("list", list);
return "boardoutput";
}
@RequestMapping(value="/detail")
public String ko4(HttpServletRequest request,Model mo) {
int num = Integer.parseInt(request.getParameter("num"));
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.boardnumcnt(num);
BoardDTO dto = ss1.boarddetail(num);
mo.addAttribute("dto", dto);
return "boarddetail";
}
@RequestMapping(value="/delete")
public String ko5(HttpServletRequest request) {
int num = Integer.parseInt(request.getParameter("num"));
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.delete(num);
return "redirect:boardout";
}
@RequestMapping(value="/reply")
public String ko6(HttpServletRequest request,Model mo) {
int num = Integer.parseInt(request.getParameter("num"));
Service1 ss1 = sqlsession.getMapper(Service1.class);
BoardDTO dto = ss1.reply(num);
mo.addAttribute("dto", dto);
return "reply";
}
@RequestMapping(value="/replysave")
public String ko7(HttpServletRequest request) {
int num = Integer.parseInt(request.getParameter("num"));
int groups = Integer.parseInt(request.getParameter("groups"));
int step = Integer.parseInt(request.getParameter("step"));
int indent = Integer.parseInt(request.getParameter("indent"));
String writer = request.getParameter("writer");
String title = request.getParameter("title");
String content = request.getParameter("content");
Service1 ss1 = sqlsession.getMapper(Service1.class);
//새 댓글이 들어오기전 자리만들어주기 (조건에 해당되는 기존댓글 아래로 다 내리기)
stepup(groups,step);
step++;
indent++;
ss1.replyinsert(num,writer,title,content,groups,step,indent);
return "redirect:boardout";
}
public void stepup(int groups,int step) {
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.stepup(groups, step);
}
}
'SPRING' 카테고리의 다른 글
230315_게시판 (0) | 2023.03.15 |
---|---|
230314_게시판 (0) | 2023.03.14 |
230310_AJAX (0) | 2023.03.10 |
230309_AJAX (0) | 2023.03.09 |
230308_AJAX (0) | 2023.03.08 |
댓글