jspblog : delete reply
This commit is contained in:
@@ -12,7 +12,9 @@ public class ForbiddenUrlConfig implements Filter {
|
|||||||
HttpServletRequest request = (HttpServletRequest) req;
|
HttpServletRequest request = (HttpServletRequest) req;
|
||||||
HttpServletResponse response = (HttpServletResponse) resp;
|
HttpServletResponse response = (HttpServletResponse) resp;
|
||||||
|
|
||||||
if (request.getRequestURI().equals("/jspblog/") || request.getRequestURI().equals("/jspblog/index.jsp")) {
|
String exception = request.getRequestURI();
|
||||||
|
|
||||||
|
if (exception.equals("/jspblog/") || exception.equals("/jspblog/index.jsp") || exception.equals("/jspblog/user/jusoPopup.jsp")) {
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
} else {
|
} else {
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ReplyDao {
|
public class ReplyDao {
|
||||||
public int save(SaveReqDto dto) {
|
public int save(SaveReqDto dto) {
|
||||||
System.out.println(dto);
|
|
||||||
String sql = "insert into reply(userId, boardId, content, createDate) values(?, ?, ?, now())";
|
String sql = "insert into reply(userId, boardId, content, createDate) values(?, ?, ?, now())";
|
||||||
Connection conn = DB.getConnection();
|
Connection conn = DB.getConnection();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
@@ -69,7 +68,7 @@ public class ReplyDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Reply> findAll(int boardId) {
|
public List<Reply> findAll(int boardId) {
|
||||||
String sql = "select * from reply where boardId= order by desc";
|
String sql = "select * from reply where boardId=? order by createDate desc";
|
||||||
Connection conn = DB.getConnection();
|
Connection conn = DB.getConnection();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -97,4 +96,23 @@ public class ReplyDao {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int deleteById(int id) {
|
||||||
|
String sql = "delete from reply where id=?";
|
||||||
|
Connection conn = DB.getConnection();
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
pstmt = conn.prepareStatement(sql);
|
||||||
|
pstmt.setInt(1, id);
|
||||||
|
int result = pstmt.executeUpdate();
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
DB.close(conn, pstmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,8 @@ public class ReplyService {
|
|||||||
public List<Reply> 댓글목록보기(int boardId) {
|
public List<Reply> 댓글목록보기(int boardId) {
|
||||||
return replyDao.findAll(boardId);
|
return replyDao.findAll(boardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int 댓글삭제(int id) {
|
||||||
|
return replyDao.deleteById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ public class ReplyController extends HttpServlet {
|
|||||||
Script.responseData(response, responseData);
|
Script.responseData(response, responseData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "delete" : {
|
||||||
|
int id = Integer.parseInt(request.getParameter("id"));
|
||||||
|
int result = replyService.댓글삭제(id);
|
||||||
|
|
||||||
|
CommonRespDto<String> dto = new CommonRespDto<>();
|
||||||
|
dto.setStatusCode(result);
|
||||||
|
|
||||||
|
String jsonData = new Gson().toJson(dto);
|
||||||
|
Script.responseData(response, jsonData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,9 @@
|
|||||||
<strong class="text-primary">${reply.userId}</strong>
|
<strong class="text-primary">${reply.userId}</strong>
|
||||||
<p>${reply.content}</p></div>
|
<p>${reply.content}</p></div>
|
||||||
<div class="m-2">
|
<div class="m-2">
|
||||||
|
<c:if test="${sessionScope.principal.id == reply.userId}">
|
||||||
<i onClick="deleteReply(${reply.id})" class="material-icons">delete</i>
|
<i onClick="deleteReply(${reply.id})" class="material-icons">delete</i>
|
||||||
|
</c:if>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|||||||
@@ -11,7 +11,15 @@ function addReply(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteReply(id) {
|
function deleteReply(id) {
|
||||||
console.log(id);
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: "/jspblog/reply?cmd=delete&id="+id,
|
||||||
|
dataType: "json"
|
||||||
|
}).done(function (result){
|
||||||
|
if (result.statusCode === 1){
|
||||||
|
$("#reply-"+id).remove();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function replySave(userId, boardId) {
|
function replySave(userId, boardId) {
|
||||||
@@ -31,6 +39,7 @@ function replySave(userId, boardId) {
|
|||||||
}).done(function (result){
|
}).done(function (result){
|
||||||
if (result.statusCode === 1){
|
if (result.statusCode === 1){
|
||||||
addReply(result.data);
|
addReply(result.data);
|
||||||
|
$("#reply__write__form").val("");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user