Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
d9886066
Commit
d9886066
authored
May 23, 2020
by
ZhengJie
Browse files
[代码完善](v2.5): v2.5 beta 用户头像裁剪上传
更新详情:
https://www.ydyno.com/archives/1225.html
parent
7a2fbae8
Changes
3
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
View file @
d9886066
...
...
@@ -168,9 +168,8 @@ public class UserController {
@ApiOperation
(
"修改头像"
)
@PostMapping
(
value
=
"/updateAvatar"
)
public
ResponseEntity
<
Object
>
updateAvatar
(
@RequestParam
MultipartFile
file
){
userService
.
updateAvatar
(
file
);
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
public
ResponseEntity
<
Object
>
updateAvatar
(
@RequestParam
MultipartFile
avatar
){
return
new
ResponseEntity
<>(
userService
.
updateAvatar
(
avatar
),
HttpStatus
.
OK
);
}
@Log
(
"修改邮箱"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
View file @
d9886066
...
...
@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
...
...
@@ -73,8 +74,9 @@ public interface UserService {
/**
* 修改头像
* @param file 文件
* @return /
*/
void
updateAvatar
(
MultipartFile
file
);
Map
<
String
,
String
>
updateAvatar
(
MultipartFile
file
);
/**
* 修改邮箱
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
d9886066
...
...
@@ -167,7 +167,7 @@ public class UserServiceImpl implements UserService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateAvatar
(
MultipartFile
multipartFile
)
{
public
Map
<
String
,
String
>
updateAvatar
(
MultipartFile
multipartFile
)
{
User
user
=
userRepository
.
findByUsername
(
SecurityUtils
.
getCurrentUsername
());
String
oldPath
=
user
.
getAvatarPath
();
File
file
=
FileUtil
.
upload
(
multipartFile
,
properties
.
getPath
().
getAvatar
());
...
...
@@ -178,6 +178,7 @@ public class UserServiceImpl implements UserService {
FileUtil
.
del
(
oldPath
);
}
redisUtils
.
del
(
"user::username:"
+
user
.
getUsername
());
return
new
HashMap
<
String
,
String
>(){{
put
(
"avatar"
,
file
.
getName
());}};
}
@Override
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment