반응형
ResponseDTO.java
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResponseDTO <T>{
private String error;
private List<T> data;
}
Hello.java
import com.example.demo230123.dto.ResponseDTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
public class Hello {
@GetMapping("/testResponseBody")
public ResponseDTO<String> testControllerRequestBody(){
List<String> list = new ArrayList<String>();
list.add("hello world I'm ResponseDTO");
ResponseDTO<String> res = ResponseDTO.<String>builder().data(list).build();
return res;
}
@GetMapping("/testResponseEntity")
public ResponseEntity<?> testControllerRequestEnitity(){
List<String> list = new ArrayList<String>();
list.add("hello world I'm ResponseEntity And you got 400 !");
ResponseDTO<String> res = ResponseDTO.<String>builder().data(list).build();
return ResponseEntity.badRequest().body(res);
}
}
restApi Test
가끔 http 상태코드( ResponseEntity ) 변경 해야 할때..까먹어서 적어둠
반응형
':::: 개발 :::: > └ JSP & SPRING' 카테고리의 다른 글
spring jpa Junit 테스트 (0) | 2023.04.22 |
---|---|
인텔리제이 could not find mysql:mysql-connector-java (7) | 2023.04.19 |
JPA Specification ( 조회 조건 조합 다이나믹 쿼리) (0) | 2022.07.28 |
@PostConstruct 어노테이션 (0) | 2020.11.13 |
spring boot 로딩된 bean 목록 출력 소스... (0) | 2020.11.13 |
spring boot rest api 애러 처리 (0) | 2020.11.09 |
@ResponseBody response 처리 혹은 예외 처리 (0) | 2020.11.05 |
spring @RequestBody Map<String, Object> Json 핸들링 (0) | 2020.10.30 |