mirror of https://github.com/elunez/eladmin
parent
7a2fbae8b6
commit
d9886066f3
|
@ -168,9 +168,8 @@ public class UserController {
|
||||||
|
|
||||||
@ApiOperation("修改头像")
|
@ApiOperation("修改头像")
|
||||||
@PostMapping(value = "/updateAvatar")
|
@PostMapping(value = "/updateAvatar")
|
||||||
public ResponseEntity<Object> updateAvatar(@RequestParam MultipartFile file){
|
public ResponseEntity<Object> updateAvatar(@RequestParam MultipartFile avatar){
|
||||||
userService.updateAvatar(file);
|
return new ResponseEntity<>(userService.updateAvatar(avatar), HttpStatus.OK);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("修改邮箱")
|
@Log("修改邮箱")
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,8 +74,9 @@ public interface UserService {
|
||||||
/**
|
/**
|
||||||
* 修改头像
|
* 修改头像
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
|
* @return /
|
||||||
*/
|
*/
|
||||||
void updateAvatar(MultipartFile file);
|
Map<String, String> updateAvatar(MultipartFile file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改邮箱
|
* 修改邮箱
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateAvatar(MultipartFile multipartFile) {
|
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
|
||||||
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
|
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
|
||||||
String oldPath = user.getAvatarPath();
|
String oldPath = user.getAvatarPath();
|
||||||
File file = FileUtil.upload(multipartFile, properties.getPath().getAvatar());
|
File file = FileUtil.upload(multipartFile, properties.getPath().getAvatar());
|
||||||
|
@ -178,6 +178,7 @@ public class UserServiceImpl implements UserService {
|
||||||
FileUtil.del(oldPath);
|
FileUtil.del(oldPath);
|
||||||
}
|
}
|
||||||
redisUtils.del("user::username:" + user.getUsername());
|
redisUtils.del("user::username:" + user.getUsername());
|
||||||
|
return new HashMap<String,String>(){{put("avatar",file.getName());}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue