Skip to content

Commit 38bc0f5

Browse files
authored
Merge pull request #243 from WhereAreYouPJ/sij
공지 이미지 업로드
2 parents f06786c + adba86b commit 38bc0f5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

presentation/src/main/java/way/presentation/admin/controller/PolicyController.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ public String getPolicyPage() {
1111
return "policy";
1212
}
1313

14+
@GetMapping("/upload")
15+
public String upload() {
16+
17+
return "upload";
18+
}
19+
1420
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>이미지 업로드</title>
6+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
7+
</head>
8+
<body>
9+
<h2>이미지 업로드</h2>
10+
<form id="uploadForm" enctype="multipart/form-data">
11+
<label for="homeImage">이미지 선택:</label>
12+
<input type="file" id="homeImage" name="homeImage" accept="image/*" required>
13+
<button type="submit">업로드</button>
14+
</form>
15+
16+
<script>
17+
$(document).ready(function () {
18+
$('#uploadForm').on('submit', function (event) {
19+
event.preventDefault();
20+
let formData = new FormData(this);
21+
22+
$.ajax({
23+
url: '/admin/image',
24+
type: 'POST',
25+
data: formData,
26+
processData: false,
27+
contentType: false,
28+
success: function (response) {
29+
alert('이미지 업로드 성공!');
30+
},
31+
error: function (xhr, status, error) {
32+
alert('업로드 실패: ' + xhr.responseText);
33+
}
34+
});
35+
});
36+
});
37+
</script>
38+
</body>
39+
</html>

0 commit comments

Comments
 (0)