Spring
[Spring] 파일 입출력
sweetseonah1004
2024. 10. 21. 14:45
create table image(
imageid int primary key auto_increment,
path varchar(10000) not null,
bid int not null
);
사용할 image table과 데이터 필요!
이미지를 변경하거나 업로드하는 로직 추가
view에서 넘겨 줘야할 데이터 hidden으로 보내주고 있음
미리보기 preview.js 파일
board.jsp로 올 때
data만 보내는 것이 아니라 image의 path도 전달 해야하기 떄문에
command 객체를 추가
이미지 업로드를 활요하는 DTO에 멤버변수로 MultipartFile타입을 추가!!
스프링에서 제공해주고 있다.
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
안되면 pom.xml에 추가
multifile
Resolver가 필요
updateBoard.do에서
getFile();로 가져올 수 있다.
만약에 에러가 나거나 잘 되지 않는 경우
서버 >> 톰캣 >> context.xml
<Context allowCasualMultipartParsing="true">
추가!