设置--修改--修改默认头像简介昵称 修改判断上传头像文件是否为空的判断
This commit is contained in:
parent
c1821c76cd
commit
baf239473e
@ -546,6 +546,8 @@ public class AppSystemController extends BaseController {
|
||||
|
||||
return ajax;
|
||||
}
|
||||
|
||||
// 更新个人信息
|
||||
@Transactional
|
||||
@PostMapping("/updateNickSign")
|
||||
public AjaxResult updateUserInfo(@RequestParam("updateNickSignDto") String updateNickSignDt,@RequestParam("avatar") MultipartFile avatarImage)
|
||||
@ -570,41 +572,41 @@ public class AppSystemController extends BaseController {
|
||||
}
|
||||
|
||||
String localPath = RuoYiConfig.getProfile();
|
||||
//头像图片
|
||||
if (avatarImage.isEmpty()) {
|
||||
return error("头像文件为空");
|
||||
}
|
||||
// String mimeType = avatarImage.getContentType();
|
||||
|
||||
//头像图片---可以为空
|
||||
if (!avatarImage.isEmpty()) {
|
||||
// String mimeType = avatarImage.getContentType();
|
||||
// System.out.println(mimeType);
|
||||
// 验证文件类型(可选,这里只允许jpg,jpeg和png格式)
|
||||
String fileType = avatarImage.getContentType().split("/")[1].toLowerCase();
|
||||
// 验证文件类型(可选,这里只允许jpg,jpeg和png格式)
|
||||
String fileType = avatarImage.getContentType().split("/")[1].toLowerCase();
|
||||
// System.out.println(avatarImage.getContentType());
|
||||
System.out.println(fileType);
|
||||
if (!"jpg".equals(fileType) && !"jpeg".equals(fileType) && !"png".equals(fileType)) {
|
||||
return error("只支持jpg、jpeg和png格式的图片");
|
||||
}
|
||||
String filePath = localPath + "/avatar";
|
||||
try {
|
||||
// 保存文件到服务器
|
||||
avatarImage.transferTo(new File(filePath, userName+"_avatar.jpg"));
|
||||
boolean flag = sysUserService.updateUserAvatar(userName,filePath+"/"+userName+"_avatar.jpg");
|
||||
if (flag){
|
||||
AjaxResult ajax = success();
|
||||
ajax.put("上传头像地址", filePath+"/"+userName+"_avatar.jpg");
|
||||
return ajax;// 可以返回文件的相对路径或URL给前端
|
||||
System.out.println(fileType);
|
||||
if (!"jpg".equals(fileType) && !"jpeg".equals(fileType) && !"png".equals(fileType)) {
|
||||
return error("只支持jpg、jpeg和png格式的图片");
|
||||
}
|
||||
else{
|
||||
return error("修改头像失败");
|
||||
String filePath = localPath + "/avatar";
|
||||
try {
|
||||
// 保存文件到服务器
|
||||
avatarImage.transferTo(new File(filePath, userName+"_avatar.jpg"));
|
||||
boolean flag = sysUserService.updateUserAvatar(userName,filePath+"/"+userName+"_avatar.jpg");
|
||||
if (flag){
|
||||
AjaxResult ajax = success();
|
||||
ajax.put("上传头像地址", filePath+"/"+userName+"_avatar.jpg");
|
||||
return ajax;// 可以返回文件的相对路径或URL给前端
|
||||
}
|
||||
else{
|
||||
return error("修改头像失败");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return error("头像文件上传失败");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return error("头像文件上传失败");
|
||||
}
|
||||
|
||||
return success("修改信息成功");
|
||||
|
||||
|
||||
// return AjaxResult.success();
|
||||
}
|
||||
@PostMapping("/createWork")
|
||||
public AjaxResult createWork(@RequestParam("userWorkDto") String userWorkDto
|
||||
|
||||
Loading…
Reference in New Issue
Block a user