jspblog : common response dto
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.example.jspblog.domain.board.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DeleteResDto {
|
|
||||||
private String status;
|
|
||||||
}
|
|
||||||
@@ -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();
|
||||||
|
|||||||
@@ -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("삭제 실패");
|
||||||
|
|||||||
Reference in New Issue
Block a user