[JAVA] Reflection 활용하여 객체 필드 복사하기 [원본 객체에서 필드 값을 읽어 대상 객체에 값 설정]
·
◎ Java/Java☕
- Reflection 활용하여 객체 필드 복사하기public class ReflectionExample { public static void copyFields(Object source, Object target) throws Exception { Class sourceClass = source.getClass(); Class targetClass = target.getClass(); Field[] sourceFields = sourceClass.getDeclaredFields(); for (Field sourceField : sourceFields) { try { Field targetField = ..
[Error Note] java.lang.IllegalStateException: closed 해결 방법 [ResponseBody.string()을 여러 번 호출]
·
◈ Study/에러노트(Error Note)🧱
- java.lang.IllegalStateException: closed 해결 방법 java.lang.IllegalStateException: closed at okio.RealBufferedSource.select(RealBufferedSource.kt:218) at okhttp3.internal.Util.readBomAsCharset(Util.kt:265) at okhttp3.ResponseBody.string(ResponseBody.kt:187) at G2B.g2b.service.BidService.testAPI(BidService.java:716) at G2B.g2b.controller.MainController.index(MainController.java:20) at java.base/jdk..
[Spring] ResponseEntity의 유용한 메소드들 [200 OK, 400 Bad Request, 404 Not Found, 201 Created 등]
·
▣ Framework/Spring🍃
- ResponseEntity의 유용한 메소드들1. ResponseEntity.ok(): 200 OK 응답 반환return ResponseEntity.ok("성공");2. ResponseEntity.badRequest(): 400 Bad Request 응답 반환return ResponseEntity.badRequest().body("잘못된 요청입니다.");3. ResponseEntity.notFound(): 404 Not Found 응답 반환return ResponseEntity.notFound().build();4. ResponseEntity.created(): 201 Created 응답 반환 (새로운 리소스 생성 시)URI location = URI.create("/resource/1");return..
[Spring] ResponseEntity란? [HTTP 응답을 생성할 때 매우 유용한 클래스]
·
▣ Framework/Spring🍃
- ResponseEntity란?ResponseEntity는 Spring에서 HTTP 응답을 생성할 때 매우 유용한 클래스이다. 상태 코드, 헤더, 본문을 자유롭게 조작할 수 있기 때문에 다양한 HTTP 응답을 세밀하게 제어할 수 있다.- 기본 사용법 // 기본적인 ResponseEntity 사용 예시ResponseEntity response = new ResponseEntity(body, HttpStatus.OK);- 주요 사용 예시들 1) 기본적인 응답 ResponseEntity.ok() : 상태 코드 200 OK와 함께 응답 본문 반환 @ResponseBody@PostMapping("/example")public ResponseEntity example() { // 정상적으로 처리된 응답 ..
[Linux] 리눅스에 수동으로 Java 설치하기 [wget 없이 Java 17 설치하는 법]
·
▣ OS : 운영체제/Linux🐧
- 리눅스에 수동으로 Java 설치하기폐쇄망에 Java를 설치해야 할 일이 있어 수동 설치 방법을 남겨놓는다. (폐쇄망에서는 wget이 안되기 때문!)아래의 링크에서 리눅스에서 사용할 Java의 버전을 다운로드 받는다. Download the Latest Java LTS FreeSubscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts.www.oracle.com # 리눅스에 올리고 tar 파일 압축 해제 (다운로드는 17.0.2 버전 받았음)tar -xvf openjdk-17.0.2_linux-x64_bin.tar.gz [Linux] 리눅스에 수동으로 Tomc..