본문 바로가기

Web3

자바 웹, 파일 다운로드 구현 @GetMapping("/download/{attatchFileId}") public ResponseEntity downloadFileFromLocal(@PathVariable String attatchFileId) throws FileNotFoundException { String fileBasePath = "C:/upload/"; log.debug(attatchFileId); // FileService Optional attachFile = tipsFileService.getAttachFilebyAttachFileId(Long.parseLong(attatchFileId)); String fileName = fileBasePath + attachFile.get().getFilePhysicalName().. 2020. 3. 28.
Form 에 FormData 와 File 을 동시에 받아 Java 로 처리하기 지난 번에 이어서 이번에는 ajax 보낸 File 이 첨부된 Form 을 Java 에서 처리해보자. 환경은 자바 8, JPA, 스프링부트 2 @PostMapping(value = "/sinmungowriteForm") public ResponseEntity sinmungowriteForm( Model model, SinmungoWriteCommand sinmungoWriteCommand) { // blah blah } } 우선 File 이 첨부되어 오니 당연하게도 @PostMapping 을 써야 한다. 그리고 유심히 봐야 할 부분은 @RequestParam("fileAttach") MultipartFile multipartFile 을 쓰지 않아도 된다는 점이다. 이는 VO 객체에 이미 private Mu.. 2020. 3. 22.
ajax 로 Form 전송시 첨부파일과 함께 보내기 간단한 Web Form 전송 시에는 대부분 데이터를 $(this).serialize(); 을 사용하여 보내면 되지만, 현재 진행 중인 작업 중에 사용자의 입력내용과 첨부파일을 한번에 보내야 하는 상황이 되었다. 이것은 일반적인 Form 전송 방법이다. $("#form").submit(function(e) { e.preventDefault(); // 폼의 자체 서브밋 동작을 비활성 var form = $(this); var url = form.attr('action'); $.ajax({ type: "POST", url: url, data: form.serialize(), // 폼 요소 직렬화 success: function(data) { alert(data); // 성공시, 결과 데이터 } }); }); .. 2020. 3. 21.