728x90
프론트에서 MulitpartFormdata로 전송시에도 마찬가지로 추가 form data 컨트롤러 파라미터로 받을 수 있다.
@PostMapping("/add_content")
public ResponseEntity<?> addContent(Integer content_board_idx, Integer content_writer_idx, String content_subject, String content_text, MultipartFile content_image) throws IOException {
if(content_image==null || content_image.isEmpty()){
mainService.createContent(content_board_idx, content_writer_idx, content_subject, content_text,null);
}
else {
String filename = content_image.getOriginalFilename();
mainService.createContent(content_board_idx, content_writer_idx, content_subject, content_text,filename);
String fullPath = uploadPath + filename;
System.out.println("fullPath = " + fullPath);
content_image.transferTo(new File(fullPath));
}
return new ResponseEntity(HttpStatus.OK);
}
728x90
'백엔드 > Spring(Boot)' 카테고리의 다른 글
spring static 경로 404 (0) | 2022.08.10 |
---|---|
spring responsebody json 필드명 변경하기 (0) | 2022.08.02 |
springboot h2 인메모리 모드 설정 (0) | 2022.06.30 |
jpa @GeneratedValue (0) | 2022.04.16 |
spring rabbitMQ 사용 (0) | 2022.04.16 |