반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 스프링게시판만들기
- insert 중복방지
- 스프링게시판목록조회
- 스프링프로젝트
- dataSource설정
- mysqlinsert한글깨짐
- 이클립스db연결
- 톰캣9.0다운로드
- 스프링게시판상세보기
- 저장할때한글깨짐
- 컨트롤러url
- 이클립스데이터베이스연결
- url설정
- mybatis연결
- 게시판만들기
- 게시판상세보기
- 스프링게시판등록
- 한글깨짐해결방법
- 톰캣시작페이지설정
- insert할글깨짐
- Could not create the java Virtual Machine
- 스프링게시판insert
- HTML
- oracle
- 게시판insert
- 자바스크립트
- double-submit
- 게시판목록조회
- Java
- 전자정부프레임워크 double-submit
Archives
- Today
- Total
하루의 일상💜
[Spring] #7. 게시판 만들기_ 첨부파일 조회/수정/다운 본문
반응형
read.html
<div class="uploadResult">
<ul>
<th:block th:each="file:*{files}">
<!-- th:object="${board}"에서 오브젝트를 받아온다. -->
<li>
<a th:href="@{/file/download(fileName=${file.fileUploadPath + '/' + file.fileUuid + '_' + file.fileName})}">
<img th:if="${file.fileImageCheck}" th:src="@{/file/display(fileName=${file.fileUploadPath} + '/s_' + ${file.fileUuid} + '_' + ${file.fileName})}">
<img th:unless="${file.fileImageCheck}" th:src="@{/images/attach.png}" width="100">
</a>
<p th:text="${file.fileName + '(' + file.fileSize / 1024 + 'KB)'}"></p>
</li>
</th:block>
</ul>
</div>
수정페이지는 기존 upload와 동일하게 작성한다.
append의 Form name만 수정하기
<div class="content">
<div class="form">
<form method="post" th:action="@{/board/update}" th:object="${board}" id="updateForm">
<div class="fields">
<div class="field">
<h4>번호</h4>
<input type="text" th:field="*{boardNumber}" readonly/>
</div>
<div class="field">
<h4>*제목</h4>
<input type="text" th:field="*{boardTitle}"/>
</div>
<div class="field">
<h4>*내용</h4>
<textarea rows="6" style="resize:none" th:field="*{boardContent}"></textarea>
</div>
<div class="field">
<h4>작성자</h4>
<input type="text" th:field="*{boardWriter}" readonly/>
</div>
<div class="field">
<h4>첨부파일</h4>
<input type="file" name="upload" multiple>
</div>
<div class="field">
<div class="uploadResult">
<ul></ul>
</div>
</div>
</div>
<ul class="actions special">
<li>
<input type="submit" class="button" value="수정 완료"/>
</li>
</ul>
</form>
</div>
</div>
...
$("form#updateForm").append(text).submit();
FileController
//파일 다운로드
@GetMapping("/download")
public ResponseEntity<Resource> download(String fileName) throws UnsupportedEncodingException {
Resource resource = new FileSystemResource("C:/upload/" + fileName);
// 사용자에게 전달받은 파일의 full경로를 resorce에 전달을 한다.
HttpHeaders header = new HttpHeaders();
String name = resource.getFilename();
// 전달받은 resorce에서 해당 경로를 지우고 실제 파일이름만 가져온다. -> 다운할때에는 UUID가 삭제되고 원본 파일이름만 나와야 하기 때문에
name = name.substring(name.indexOf("_") + 1);
header.add("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "UTF-8"));
return new ResponseEntity<>(resource, header, HttpStatus.OK);
}
반응형
'SpringBoot' 카테고리의 다른 글
[Spring] #9. 게시판 만들기 _ 댓글작성/수정/삭제 (0) | 2022.12.30 |
---|---|
[Spring] #8. 게시판 만들기_ 이전페이지 페이징처리 (0) | 2022.12.29 |
[Spring] #6. 게시판만들기_첨부파일 업로드/수정/삭제 (0) | 2022.12.29 |
[Spring] #5. 게시판 만들기 _ 페이징처리 (0) | 2022.12.12 |
[Spring] #4. 게시판만들기 _ 입력받은 데이터를 화면에 보이기 (1) | 2022.11.24 |