Spring Level4 Trouble Shooting

song yuheon·2023년 9월 4일
0

Trouble Shooting

목록 보기
10/57
post-thumbnail

Postman Json으로 로그인 불능 문제

원인은 postman에서 x-www-form-urlencoded가 아닌 raw 형태로 보냈기 때문에 발생

x-www-form-urlencoded에 key - value 값으로 전달하자 문제 해결


Client로 URL이 아닌 응답 메시지 전송 문제

로그인 상태를 알려주는 controller를 만들고 해당 컨트롤러로 상태를 알려준다.

package com.sparta.springlevel4.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StatusController {

   @GetMapping("/login/success")
   public ResponseEntity<String> loginSuccess() {
       return ResponseEntity.ok("{\n\"message\": \"로그인 성공\",\n\"statusCode\": \"200\"\n}");
   }
}


                       .defaultSuccessUrl("/login/success", true)
  • Plus ( 문자열이 아닌 객체로 전송 )
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class LoginStatusDto {
    private String statusCode;
    private String message;
    public LoginStatusDto(String statusCode, String message) {
        this.statusCode = statusCode;
        this.message = message;
    }

}

로그인 상태를 전달을 위한 클래스를 만들고
StatusController에서 객체 전송으로 문제 해

profile
backend_Devloper

0개의 댓글