[백준/BOJ] 2447번: 별 찍기 - 10 - JAVA [자바]
·
◈ Coding Test/백준(BOJ)👨🏻‍💻
- 백준 2447번: 별 찍기 - 10문제재귀적인 패턴으로 별을 찍어 보자. N이 3의 거듭제곱(3, 9, 27, ...)이라고 할 때, 크기 N의 패턴은 N×N 정사각형 모양이다.크기 3의 패턴은 가운데에 공백이 있고, 가운데를 제외한 모든 칸에 별이 하나씩 있는 패턴이다.*** * * ***N이 3보다 클 경우, 크기 N의 패턴은 공백으로 채워진 가운데의 (N/3)×(N/3) 정사각형을 크기 N/3의 패턴으로 둘러싼 형태이다. 예를 들어 크기 27의 패턴은 예제 출력 1과 같다.입력첫째 줄에 N이 주어진다. N은 3의 거듭제곱이다. 즉 어떤 정수 k에 대해 N=3k이며, 이때 1 ≤ k 출력첫째 줄부터 N번째 줄까지 별을 출력한다.import java.io.BufferedReader;import ja..
[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() { // 정상적으로 처리된 응답 ..