Project/Study Website Project
[String Boot Project] 파일 업로드
seung_hyeon
2025. 1. 20. 22:22
- 테이블 변경


table 변경 시 entity도 변경
PostService

→ String project path 프로젝트 경로를 담아줌
→ 파일의 이름을 붙일 랜덤 이름 생성
→ uuid 식별자 + _ + 원래 파일 이름
→ saveFile = 파일 생성 후 projectPath에 넣고 이름 설정
PostView.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>게시글 상세 페이지</title>
</head>
<body>
<h1 th:text = "${post.title}">제목입니다.</h1>
<p th:text = "${post.content}">내용이 들어갈 부분입니다.</p>
<a th:href ="@{${post.filepath}}">사진</a>
<a th:href="@{/post/delete(id=${post.id})}">글 삭제</a>
<a th:href="@{/post/modify/{id}(id = ${post.id})}">수정</a>
</body>
</html>
th:href = a태그에 경로 걸 때 사용
th:text = 태그에 문자열을 출력할 때 사용
(변수는 $로 감싸야함)
- 실행






파일 업로드 에러 및 디버깅
[Spring Boot Project] 파일 업로드 에러 및 디버깅
첫 번째 에러파일 업로드 시 Null Point Exception 발생 디버깅controller에서 받아오는 매게 변수 이름이랑 일치해야 한다 file : null 에러 확인 name을 추
shyeeon.tistory.com