일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- jQuery
- 생명주기
- JavaScript
- 영성
- Java
- Selector
- 에디터
- 안드로이드 AVD
- 게시판
- 아이콘
- 제이쿼리
- 회원가입
- 주님의교회
- TinyMCE
- CSS
- androidstudio
- Resources
- 웹개발
- Spring
- 자바
- 인텐트
- java 8
- 청주
- Intent
- 프로그래밍
- 안드로이드
- Android
- Activity
- 글쓰기
- #청주주님의교회
- Today
- Total
공부하는 블로그
(웹개발) 댓글만들기/ 댓글에 댓글까지 본문
댓글 만들기
1)
vo 폴더에 ReplyVO 생성
2)
3) ReplyDao 생성
4) ReplyDaoImpl 생성
5) dao/sql/replyDao.xml생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="ReplyDao"> <insert id="insertNewReply" parameterType="ReplyVO"> INSERT INTO REPLY ( REPLY_ID ,WRITE_DATE ,CONTENT ,PARENT_REPLY_ID ,BOARD_ID ,ID ) VALUES ( REPLY_ID_SEQ.NEXTVAL ,SYSDATE ,#{content} ,#{parentReplyId} ,#{boardId} ,#{id} ) </insert>
<resultMap type="ReplyVO" id="ReplyVOMap"> <id column="REPLY_ID" property="replyId" /> <result column="WRITE_DATE" property="writeDate"/> <result column="CONTENT" property="content"/> <result column="PARENT_REPLY_ID" property="parentReplyId"/> <result column="BOARD_ID" property="boardId"/> <result column="ID" property="id"/> <result column="LEVEL" property="level"/> <association property="memberVO" javaType="MemberVO"> <id column="ID" property="id" /> <result column="EMAIL" property="email"/> <result column="NAME" property="name"/> <result column="NICK_NAME" property="nickName"/> <result column="PROFILE_PHOTO" property="profilePhoto"/> <result column="MAILING_YN" property="mailingYn"/> <result column="MEMO_RECEIVE_FLAG" property="memoReceiveFlag"/> </association> </resultMap>
<select id="selectAllReplyByBoardId" resultMap="ReplyVOMap" parameterType="_int"> SELECT R.REPLY_ID , R.WRITE_DATE , R.CONTENT , R.PARENT_REPLY_ID , R.BOARD_ID , M.ID , M.EMAIL , M.NAME , M.NICK_NAME , M.PROFILE_PHOTO , M.MAILING_YN , M.MEMO_RECEIVE_FLAG , LEVEL FROM REPLY R , MEMBER M WHERE R.ID = M.ID AND R.BOARD_ID = #{boardId} START WITH R.PARENT_REPLY_ID = 0 CONNECT BY PRIOR R.REPLY_ID = R.PARENT_REPLY_ID
</select> </mapper> |
조인을 위해 사용된다.
6) service / ReplyService(인터페이스) 생성
7) ReplyServiceImpl.java 생성
8) Controller 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package com.ktds.reply.web;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
import com.ktds.member.vo.MemberVO; import com.ktds.reply.service.ReplyService; import com.ktds.reply.vo.ReplyVO;
@Controller public class ReplyController { private ReplyService replyService;
public void setReplyService(ReplyService replyService) { this.replyService = replyService; }
@RequestMapping("/reply/write") @ResponseBody public ReplyVO doReplyWrite(ReplyVO replyVO, HttpSession session) {
MemberVO memberVO = (MemberVO) session.getAttribute("_USER_"); String id = memberVO.getId(); replyVO.setId(id);
boolean isSuccess = replyService.createNewReply(replyVO);
ReplyVO newReplyVO = replyVO; return newReplyVO; }
@RequestMapping("/reply/list/{boardId}") @ResponseBody public List<ReplyVO> getReplyList(@PathVariable int boardId) { return replyService.readAllReplyByBoardId(boardId); } }
|
9) pom.xml에 dependency 추가
1 2 3 4 5 | <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.1</version> </dependency> |
10)
mybatis.xml에 추가
11) replyContext 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="replyDaoImpl" class="com.ktds.reply.dao.ReplyDaoImpl"> <property name="sqlSessionTemplate" ref="sqlSessionTemplate" /> </bean>
<bean id="replyServiceImpl" class="com.ktds.reply.service.ReplyServiceImpl"> <property name="replyDao" ref="replyDaoImpl"></property> </bean> </beans>
|
12) controllerContext에 추가
13) static 추가
← 저장
css/layout-style.css 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | .reply-wrapper { border-top: 1px solid #ddd; padding-top: 15px; padding-bottom: 15px; } .img, .reply { display: inline-block; vertical-align: top; } .img { width: 70px; } .reply .writer { margin-right: 20px; font-weight: bold; } .reply .date { color: #ccc; } |
14) read.jsp파일
Javascript script 시작부분에 replyId = 0으로 선언
-- 수정 삭제 div 아래에 댓글창 보여주는 –
댓글을보여주기 위한 function
'Develop > 웹개발' 카테고리의 다른 글
날짜와 시간 입력을 도와주는 데이트 피커 15가지 (0) | 2018.04.23 |
---|---|
(웹개발) 댓글 수정/삭제 (0) | 2017.10.13 |
(웹개발) Paging (0) | 2017.10.10 |
(웹개발) Search 기능 추가하기 (0) | 2017.09.29 |
(웹개발) 삭제 기능 추가하기 (delete) (0) | 2017.09.29 |