jspblog : common response dto

This commit is contained in:
kim
2021-01-22 15:19:46 +09:00
parent 094606e426
commit 75d116b884
4 changed files with 13 additions and 16 deletions

View File

@@ -0,0 +1,9 @@
package com.example.jspblog.domain.board.dto;
import lombok.Data;
@Data
public class CommonRespDto<T> {
private int statusCode;
private T data;
}

View File

@@ -1,8 +0,0 @@
package com.example.jspblog.domain.board.dto;
import lombok.Data;
@Data
public class DeleteResDto {
private String status;
}

View File

@@ -89,15 +89,11 @@ public class BoardController extends HttpServlet {
String data = br.readLine(); String data = br.readLine();
Gson gson = new Gson(); Gson gson = new Gson();
DeleteReqDto dto = gson.fromJson(data, DeleteReqDto.class); DeleteReqDto dto = gson.fromJson(data, DeleteReqDto.class);
CommonRespDto<String> commonRespDto = new CommonRespDto<>();
int result = boardService.글삭제(dto.getBoardId()); int result = boardService.글삭제(dto.getBoardId());
DeleteResDto resDto = new DeleteResDto(); commonRespDto.setStatusCode(result);
if (result == 1) { String resData = gson.toJson(commonRespDto);
resDto.setStatus("ok");
} else {
resDto.setStatus("fail");
}
String resData = gson.toJson(resDto);
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
out.print(resData); out.print(resData);
out.flush(); out.flush();

View File

@@ -85,7 +85,7 @@
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
dataType: "json" dataType: "json"
}).done(function(result){ }).done(function(result){
if (result.status === 'ok') { if (result.statusCode === 1) {
location.href = "index.jsp"; location.href = "index.jsp";
} else { } else {
alert("삭제 실패"); alert("삭제 실패");