IT'S DO
[Spring]log4j, @Slf4j 사용법
개발/Spring Boot 2023. 1. 19. 13:40

보통 프로젝트를 진행하면서 나는 System.out.println(" 변수 내용 " + 변수); 를 사용했었다. 하지만 로그 레벨을 제어할 수 없다고 하면서, log4j를 사용하는 것이 좋다고 한다. # 첫번째 방법. build.gradle.kts 쪽에서 implementation("org.slf4j:slf4j-api:2.0.5") 써주고 gradle 빌드 해준다. 원하는 자바에 import org.slf4j.Logger; import org.slf4j.LoggerFactory; Logger logger = LoggerFactory.getLogger(getClass()); 를 넣어준다. logger.debug("result ", result); 또는 info 등 원하는 로그 레벨로 사용해준다. # 두번째..

[API] @PathVariable , @RequestBody , @RequestParam 간단한 예제
개발/API 2023. 1. 19. 11:28

@PathVariable @GetMapping("/v1/opinions/nickname/{id}") public String findUserNickname(@PathVariable final Long id) throws Exception { return opinionService.findUserNickname(id); } localhost:8080/v1/update/{id} {id}에 형식에 맞는 데이터를 넣어주면 됨. 대신에 공백x @RequestBody @PatchMapping("/v1/opinions/{id}") public Long update(@PathVariable final Long id, @RequestBody final OpinionRequestDto params) throws Excep..

[Java] 임시 폴더 경로 가져오기
개발/JAVA 2023. 1. 18. 14:23

Windows : C:\Users\User\AppData\Local\Temp Linux : /temp # 사용 방법 1. System.getProperty("java.io.tmpdir") System.getProperty("java.io.tmpdir") tmp dir 경로를 리턴함. public class til { public static void main(String[] args) { String tmpDir = System.getProperty("java.io.tmpdir"); System.out.println("tmp= " + tmpDir); } } # 로그 값 => tmp= /tmp

article thumbnail
[Java] 제공되는 타입이 일치하지 않을 때, 비 static 필드는 static 컨텍스트에서 참조할 수 없습니다. 해결법
개발/JAVA 2023. 1. 18. 11:39

# 예를 들어 제공되는 타입이 file, 현재는 string이다고 할 때, # 해결법 File folder = new File("/test/Library"); executor.setWorkingDirectory(folder); # 비 static 필드는 static 컨텍스트에서 참조할 수 없습니다. 표준의 형식을 보면 public void로 시작된다. 그래서 static 컨텍스트에서 참조할 수 없다고 하는 것. 그러면 이걸 바꿔주면 됨. # 해결 static으로 생성자를 만들어 주자. 이런 것들 많이 볼텐데, 그 때마다 원하는 문자열에 맞게 생성자를 만들어 주자