EDIT 기능 추가
This commit is contained in:
parent
7078a17073
commit
eabb7968b3
|
|
@ -123,9 +123,69 @@ public class UserProfileController {
|
|||
}
|
||||
|
||||
@PutMapping("/user/{id}")
|
||||
public void putUserProfile(@PathVariable String id, @RequestParam String name,
|
||||
@RequestParam String phone, @RequestParam String address, @RequestParam String filepath) {
|
||||
mapper.updateUserProfile(id, name, phone, address, filepath);
|
||||
public void putUserProfile(@PathVariable("id") String id, @RequestParam("name") String name,
|
||||
@RequestParam("phone") String phone, @RequestParam("address") String address,
|
||||
@RequestPart MultipartFile upfile) {
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String fileName = upfile.getOriginalFilename();
|
||||
String fileExtName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
|
||||
String contentType = upfile.getContentType();
|
||||
long fileLength = upfile.getSize();
|
||||
|
||||
System.out.println("fileLength : " + fileLength);
|
||||
System.out.println("fileName : " + fileName);
|
||||
System.out.println("fileExtName : " + fileExtName);
|
||||
System.out.println("contentType : " + contentType);
|
||||
|
||||
byte[] data = null;
|
||||
try {
|
||||
data = upfile.getBytes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String baseFolder = SERVER_URL_IMG;
|
||||
String baseMiddleFolder = "/img";
|
||||
String saveFolder = baseFolder + baseMiddleFolder;
|
||||
String dbSavePath = baseMiddleFolder + "/" + uuid + fileExtName;
|
||||
String saveFullFilePath = saveFolder + "/" + uuid + fileExtName;
|
||||
|
||||
// 입력된 내용 파일로 쓰기
|
||||
File folder = new File(saveFolder);
|
||||
// 해당 디렉토리가 없을경우 디렉토리를 생성합니다.
|
||||
if (!folder.exists()) {
|
||||
try {
|
||||
folder.mkdir(); // 폴더 생성합니다.
|
||||
System.out.println(saveFolder + " folder create OK");
|
||||
} catch (Exception e) {
|
||||
e.getStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("A folder has already been created");
|
||||
}
|
||||
|
||||
File file = new File(saveFullFilePath);
|
||||
System.out.println("saved file : " + saveFullFilePath);
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
fos = new FileOutputStream(file);
|
||||
fos.write(data);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (fos != null)
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
mapper.updateUserProfile(id, name, phone, address, dbSavePath);
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/{id}")
|
||||
|
|
|
|||
|
|
@ -18,23 +18,18 @@
|
|||
formData.append("phone", $('#phone').val());
|
||||
formData.append("address", $('#address').val());
|
||||
formData.append("upfile", $("input[name='upfile']")[0].files[0]);
|
||||
/* formData.append("upfile", $('#upfile').files[0]); */
|
||||
|
||||
for (var pair of formData.entries()) {
|
||||
console.log(pair[0]+ ', ' + pair[1]);
|
||||
}
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/profile/user/10',
|
||||
/* data: $('#theForm').serialize(), */
|
||||
data: formData,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
|
||||
success: function(data){
|
||||
//location.href="listUser.do";
|
||||
alert("신규등록 OK");
|
||||
},
|
||||
error: function(error, status, msg) {
|
||||
|
|
@ -42,6 +37,35 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
$('#edit').on('click', function() {
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append("name", $('#ename').val());
|
||||
formData.append("phone", $('#ephone').val());
|
||||
formData.append("address", $('#eaddress').val());
|
||||
formData.append("upfile", $("input[name='eupfile']")[0].files[0]);
|
||||
|
||||
for (var pair of formData.entries()) {
|
||||
console.log(pair[0]+ ', ' + pair[1]);
|
||||
}
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
url: '/profile/user/1',
|
||||
data: formData,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
|
||||
success: function(data){
|
||||
alert("수정등록 OK");
|
||||
},
|
||||
error: function(error, status, msg) {
|
||||
alert("Error " + msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -71,8 +95,15 @@
|
|||
가격 <input type="text" id="phone" name="phone" value=""/><br>
|
||||
별 <input type="text" id="address" name="address" value=""/><br>
|
||||
이미지 <input type="file" id="upfile" name="upfile">
|
||||
<button id="add" type="button" class="btn btn-primary">Submit</button>
|
||||
<button id="add" type="button">Submit</button>
|
||||
<br><br><br><br><br><br>
|
||||
|
||||
제품명 <input type="text" id="ename" name="ename" value=""/><br>
|
||||
가격 <input type="text" id="ephone" name="ephone" value=""/><br>
|
||||
별 <input type="text" id="eaddress" name="eaddress" value=""/><br>
|
||||
이미지 <input type="file" id="eupfile" name="eupfile">
|
||||
<button id="edit" type="button">Submit</button>
|
||||
|
||||
</body>
|
||||
<iframe name='blankifr' style='display:none;'></iframe>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue