From 93f14a3020e6230232208a8210c30f6c86440586 Mon Sep 17 00:00:00 2001
From: zhoufeng <27208084@qq.com>
Date: Mon, 15 Jun 2020 16:34:10 +0800
Subject: [PATCH] 修复头像上传功能

---
 src/main/java/com/huaheng/common/utils/file/FileUploadUtils.java           | 2 +-
 src/main/java/com/huaheng/pc/system/user/controller/ProfileController.java | 1 +
 src/main/resources/application.yml                                         | 2 +-
 src/main/resources/templates/system/user/profile/avatar.html               | 4 ++--
 src/main/resources/templates/system/user/profile/profile.html              | 2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/huaheng/common/utils/file/FileUploadUtils.java b/src/main/java/com/huaheng/common/utils/file/FileUploadUtils.java
index 4a49fa6..e20cde4 100644
--- a/src/main/java/com/huaheng/common/utils/file/FileUploadUtils.java
+++ b/src/main/java/com/huaheng/common/utils/file/FileUploadUtils.java
@@ -130,7 +130,7 @@ public class FileUploadUtils
         }
         if (!desc.exists())
         {
-            desc.createNewFile();
+//            desc.createNewFile();
         }
         return desc;
     }
diff --git a/src/main/java/com/huaheng/pc/system/user/controller/ProfileController.java b/src/main/java/com/huaheng/pc/system/user/controller/ProfileController.java
index 00e3490..f8dd617 100644
--- a/src/main/java/com/huaheng/pc/system/user/controller/ProfileController.java
+++ b/src/main/java/com/huaheng/pc/system/user/controller/ProfileController.java
@@ -138,6 +138,7 @@ public class ProfileController extends BaseController
             if (!file.isEmpty())
             {
                 String avatar = FileUploadUtils.upload(file);
+                user.setId(getUser().getId());
                 user.setAvatar(avatar);
                 if (userService.updateUserInfo(user) > 0)
                 {
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 166fa7e..a89d562 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -11,7 +11,7 @@ huaheng:
   #版权年份
   copyrightYear: 2018
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  profile: D:/Huaheng/uploadPath
+  profile: D:/Huaheng/uploadPath/
   # 获取ip地址开关
   addressEnabled: false
 
diff --git a/src/main/resources/templates/system/user/profile/avatar.html b/src/main/resources/templates/system/user/profile/avatar.html
index dd68e22..320ff72 100644
--- a/src/main/resources/templates/system/user/profile/avatar.html
+++ b/src/main/resources/templates/system/user/profile/avatar.html
@@ -24,12 +24,12 @@
     </div>
 <div th:include="include::footer"></div>
 <script th:src="@{/ajax/libs/cropbox/cropbox.js}"></script>
-<script type="text/javascript">
+	<script th:inline="javascript">
 $(window).load(function() {
     var options = {
         thumbBox: '.thumbBox',
         spinner: '.spinner',
-        imgSrc: '/wms/img/profile.jpg'
+        imgSrc: '/wms/profile/' + [[${user.avatar}]]
     }
     var cropper = $('.imageBox').cropbox(options);
     $('#avatar').on('change',
diff --git a/src/main/resources/templates/system/user/profile/profile.html b/src/main/resources/templates/system/user/profile/profile.html
index 37892d7..fd972b7 100644
--- a/src/main/resources/templates/system/user/profile/profile.html
+++ b/src/main/resources/templates/system/user/profile/profile.html
@@ -35,7 +35,7 @@
                     <div class="contact-box">
 	                        <div class="col-sm-4">
 	                            <div class="text-center">
-	                                <img alt="image" class="img-circle m-t-xs img-responsive" th:src="(${user.avatar} == '') ? '../../img/profiles.jpg' : '/profile/' + ${user.avatar}">
+	                                <img alt="image" class="img-circle m-t-xs img-responsive" th:src="(${user.avatar} == '') ? '../../img/profiles.jpg' : '../../profile/' + ${user.avatar}">
 	                                <div class="m-t-xs font-bold">[[${user.loginIp}]]</div>
 	                            </div>
 	                        </div>
--
libgit2 0.22.2