Java(156)
-
STS 사용하지 않는 import 제거 단축키
Ctrl + Shift + O
2024.12.27 -
Mybatis insert후 키값 반환하기
쿼리 SELECT to_char(current_timestamp,'yyyymmdd')||lpad(nextval('seq_test')::TEXT, 3, '0') INSERT INTO test( id, name ) VALUES ( #{id}, #{name} )서비스public String create(Map attach) { testMapper.create(attach); return attach.get("id").toString(); // Retrieve pre-generated ID}
2024.12.27 -
Spring boot 업로드 파일명 중복 피하기
filePath 정보를 계속 변경해서 while문으로 존재여부를 확인하는게 중요@PostMapping("/upload")public ResponseEntity handleFileUpload(@RequestParam("file") MultipartFile file) throws IOException { // Define the directory where files will be saved String uploadDir = "uploads/"; // Ensure the directory exists Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectorie..
2024.12.26 -
Spring boot 파일업로드 OutOfMemoryError 고려사항
작은 파일public Map upload(@RequestParam("file") MultipartFile file) { Path filePath = uploadPath.resolve(file.getOriginalFilename()); Files.write(filePath, file.getBytes());큰 파일public Map upload(@RequestParam("file") MultipartFile file) { Path filePath = uploadPath.resolve(newFilename); Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
2024.12.26 -
Spring boot 업로드 디렉토리 설정하기
application.ymlfile: upload-dir: /path/uploadsController@Value("${file.upload-dir}")private String uploadDir;
2024.12.26 -
Spring boot Sencha 연동 파일 업로드 구성
Map을 통해서 응답 처리해야 함Case1@PostMapping("/location/upload")public ResponseEntity uploadFile(@RequestParam("file") MultipartFile file) { try { // Handle file storage Path path = Paths.get("uploads/" + file.getOriginalFilename()); Files.write(path, file.getBytes()); // Success response return ResponseEntity.ok(Map.of("success", true, "message", "File uploaded succ..
2024.12.26