IT (39) 썸네일형 리스트형 spring file delete 매번 프로젝트 들어갈때마다 곤란하고 구글링했던 파일 삭제 관련 파일을 삭제하기위한 util class를 호출한다. 1 2 3 4 5 6 public int delete(Long orderId) throws Exception{ Path path = Paths.get(디비에서 조회한 파일의 path); boolean isDeleted = FileStorageUtils.delete(path, 디비에서 조회한 파일의 이름); return deletCnt; } Colored by Color Scripter cs 실제 파일 삭제 util class 1234567891011121314151617181920212223 public static boolean delete(final Path path, final Stri.. spring 파일 다운로드 매번 프로젝트 들어갈때마다 헷갈렸던 파일관련 ...구글링하기 귀찮아서 작성 Controller 1 2 3 4 5 6 7 8 9 10 public ResponseEntity download(HttpServletRequest request, HttpServletResponse response){ try { File file = fileUploadService.download(필요한파라미터); response.setContentType("application/octet-stream; charset=utf-8;"); response.setHeader("Content-Disposition", Utils.getDisposition(file.getName(), Utils.checkBrowser(request))); .. spring 파일 업로드 매번 프로젝트에 투입될때마다 고민하고 구글링하는걸 방지하고자 작성합니다. 파일 업로드, 다운로드, 삭제에 대한 API를 정의해놓기 파일업로드는 @RequestParam으로 MultipartFile을 파라미터로 받던지 @RequestBody에 받던지 상관없고 파일을 받아서 실제 저장할 물리적 위치를 정의해준다. 1 2 3 4 5 6 7 8 9 10 11 12 13 public String upload(Long orderId, MultipartFile file) throws Exception { //파일 path를 정의해준다. Path saveRepoPath = Paths.get(rootStoragePath, fileStoragePath, String.valueOf(orderId)); //파일 데이터에서 이.. no suitable constructor found for type 에러 분석 Json데이터를 model데이터로 변환할때 no suitable constructor found for type 해당에러가 발생하는데 이유가 되는 좋은 블로그 공유 이유인 즉, Hoge hello = mapper.readValue(json, Hello.class); json데이터가 위의 class로 맵핑되는 시점에 해당 메소드를 호출하면서 default constructor를 호출하게 되는데 없으면 위와같은 에러가 발생하는것!!! interviewbubble.com/jsonmappingexception-no-suitable-constructor-found-for-type-simple-type-class-can-not-instantiate-from-json-object/ [Solved]: com.faste.. spring junit test service단에서 @value annotaion으로 properties파일에 설정되어있는 값을 불러와서 사용하는 경우가 있다. 아래와 같이 service를 하나 만들고 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 @Service public class StudentService{ // 이런식으로 불러와서 값을 셋팅 @Value("${host.url}") private String host; private StudentRepository studentRepository; public StudentService(StudentRepository studentRepository){ this.studentRepository = studentRepository;.. JAVA 상대경로 JAVA에서 주로 file작업을 할때 위치를 찾는 작업을 많이합니다. / ==> root 디렉토리 ./ ==> 현재 디렉토리 ../ ==> 현재 디렉토리의 상위경로 예를들어 /var/ssc/classes/com/ssc/controller/MemberControll.class 파일이 있고 /var/ssc/load.txt 라는 파일이 있습니다. MemberController.class 파일에서 load.txt라는 파일을 찾기위해선 new File("./load.txt"); 라고 명시하면 됩니다. JAVA는 HTML에서와 다르게 ssc의 경로 즉, 프로젝트에서 경로가 시작되기 때문에 ./ ==> 현재 디렉토리로 명시하면 됩니다. JAVA 입력과 출력 stream java.io 패키지의 개요 Provides for system input and output through data streams, serialization and the file system. 데이터 스트림을 통한 시스템 입력 및 출력 제공, 직렬화 파일시스템 stream > byte단위로 파일을 쓰고 읽는다. 즉, 우리가 서버에 업로드와 다운로드시 파일은 byte단위로 작업됩니다. 저는 Spring batch에서 csv파일을 읽어 데이터 작업을 한 후 완료파일을 excel로 만드는 작업을 했습니다. 그 엑셀은 배치완료시점에 다운받는게 아닌 엑셀파일을 FTP올리고(쓰고) 사용자가 언제든지 다운받을 수 있도록 해야했습니다. 일반적인 JSP에서의 엑셀다운로드가 아니였습니다. 1 2 3 4 5 6 7 8 .. MariaDB & Mysql 버전 확인 MariaDB / Mysql 버전 확인 방법입니다. 1 SELECT VERSION() cs 감사합니다. 이전 1 2 3 4 5 다음