2023.05.03 - [Spring] - spring vue 연동 상품 관리,게시판 관리 어드민 페이지 03
이전글에서 patch시 405 에러가 나왔는데요
백엔드에서는 문제가 없이 200 ok가 되었습니다.
그래서 백엔드에서 return을 할때 index.html( view를 빌드 하였기 때문에 index.html을 이용) redirect를 했는데 여기서
라우터가 못찾는것 같더라고요. 그래서 해결법으로는 리턴을 성공시 200ok보내주고 실패시 bad request를 보내주기로 판단 하였습니다.
해결법 : return ResponseEntity.ok().build();
@PatchMapping("/api/Notice/Patch/{id}")
public ResponseEntity<?> updatePatch(@PathVariable Long id, @RequestBody Notice newNotice) {
try{
System.out.println("/api/Notice/Patch");
noticeService.update(id,newNotice);
}catch (Exception e){
e.printStackTrace();
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok().build();
}
이렇게하면 axios에서 올바르게 response 되었다 판단하여 try catch쪽으로 넘어가지않고 올바르게 됩니다. 여기서
vue를 새로고침하였습니다.
this.axios.patch(`/api/Notice/Patch/${postId}`, data,config)
.then(response => {
alert('게시판 수정 완료');
this.$router.go(0);
})
.catch(error => {
alert('게시판 수정 실패');
console.log(error);
});
올바르게 작동하였습니다.
'웹 > Spring vue 웹 개발' 카테고리의 다른 글
spring vue 연동 상품 관리,게시판 관리 어드민 페이지 완료 (0) | 2023.05.16 |
---|---|
spring vue 연동 상품 관리,게시판 관리 어드민 페이지 05 (1) | 2023.05.15 |
spring vue 연동 상품 관리,게시판 관리 어드민 페이지 03 (0) | 2023.05.03 |
spring vue 연동 상품 관리,게시판 관리 어드민 페이지 02 (0) | 2023.05.02 |
spring vue 연동 게시판 완료(ui는 조금더 수정예정), 상품 관리,게시판관리 어드민 페이지 01 (0) | 2023.04.30 |