@Transactional(rollbackFor?=?Exception.class)
public?boolean?addAccount(User?account)?{
????//密碼加鹽MD5
????account.setPasswd(HashUtils.encryPassword(account.getPasswd()));
????//頭像保存到本地
????List<String>?imageList?=?fileService.getImagePath(Lists.newArrayList(account.getAvatorFile()));
????if?(!imageList.isEmpty()){
?????account.setAvator(imageList.get(0));//將相對路徑設置進去
????}
????BeanHelper.setDefaultProp(account,User.class);
????BeanHelper.onInsert(account);
????userMapper.insert(account);
????account.setEnable(0);
????mailService.registerNotify(account.getEmail());
????return?true;
}
file:
??path:?D:/pic@Value("${file.path:}")
private?String?filePath;
/**
?*?將上傳文件返回一個列表路徑,因為我們存儲到數(shù)據(jù)庫里面知識一個路徑,不是一個文件,我們的文件是要保存到本地的
?*/
public?List<String>?getImagePath(List<MultipartFile>?files){
????List<String>?paths?=?Lists.newArrayList();
????//對每個上傳的每個文件進行操作
????files.forEach(file?->?{
????????File?localFile?=?null;
????????if?(!file.isEmpty()){
????????????try?{
????????????localFile?=?saveToLocal(file,filePath);
????????????String?path?=?StringUtils.substringAfterLast(localFile.getAbsolutePath(),filePath);
????????????paths.add(path);
????????????}catch(IOException?e){
????????????????throw?new?IllegalArgumentException(e);
????????????}
????????}
????});
????return?paths;
}
2018-12-29?17:55:52.617??INFO?12720?---?[?qtp98801744-35]?com.yxs.house.web.filter.LogFilter???????:
?request---coming...2018-12-29?17:55:52.743?ERROR?12720?---?[?qtp98801744-35]?c.yxs.house.web.controller.ErrorHandler??:
??nulljava.lang.NullPointerException:?null at?com.yxs.house.biz.service.FileService.lambda$getImagePath$0(FileService.java:31)?~[classes/:na]
?? at?com.yxs.house.biz.service.FileService$$Lambda$17/1558917749.accept(Unknown?Source)?~[na:na] at?java.util.ArrayList.forEach(ArrayList.java:1249)?
?? ~[na:1.8.0_25] at?com.yxs.house.biz.service.FileService.getImagePath(FileService.java:29)?~[classes/:na]
?? at?com.yxs.house.biz.service.UserService.addAccount(UserService.java:56)?~[classes/:na]
提交表單之后報空指針異常?
慕數(shù)據(jù)017433
2018-12-29 17:57:09