我有偏upating我的網頁的問題。 我很少解釋商業問題。我有用戶配置文件,在那裏他可以改變你自己 等技能,個人信息,主要寫真照片Galerry的任何信息。 所有的工作很好,但我有一個惱人想以後等照片添加阿賈克斯後法與彈簧偏清爽thymealf
首先,我展示了主要的相片中添加究竟
<div th:fragment="photoDiv">
<img id="mainPhoto" th:src="@{/profile/main/img}" alt=""/>
<div >
<form id="mainPhotoForm" action="#"th:action="@{/profile/main/upload}"
enctype="multipart/form-data" method="post">
<label for="files" ><img src="../../img/plus.png"/> Upload photo</label>
<input id="files" style="display:none;" type="file" accept='image/*'th:name="img" onchange="document.getElementById('mainPhotoForm').submit();"/>
</form>
</div>
</div>
我控制器
@PostMapping("/profile/main/img")
public String uploadingMianPhoto(@RequestParam("img") MultipartFile file, @ModelAttribute("userDto") userDto user) {
String path = filesStrorage.storeFiles(file, getCurrentUserID());
if(!path.isEmpty()) {
Photo mainPhoto = new Photo();
mainPhoto.setFileName(file.getOriginalFilename());
mainPhoto.setPath(path);
user.setProfilePhoto(mainPhoto);
}
return "/profile/edit";
}
/**
* Load mian photo
**/
@RequestMapping(value="/profile/main/upload")
public @ResponseBody
byte[] mainPhotoResponse(@ModelAttribute("userDto") UserDto user) throws IOException {
Path path = Paths.get(user.getProfilePhoto().getPath());
return Files.readAllBytes(path);
}
我只希望我的整個頁面刷新更新th:fragment="photoDiv"
不是整個頁面
我嘗試AJAX片段更新,但我不使用彈簧的Webflow,我應該加入SPRIN g weblow配置,或者我可以通過jQuery來做到這一點?
所以後試圖
我uploadingMianPhoto return "/profile/edit :: photoDiv"
增加,但它只返回我,我的整個頁面上僅此片段
請給我ajax開機自檢功能的一些exaples,巫婆幾個解釋的話