提交表单之后报空指针异常?

@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;

/**
 * 将上传文件返回一个列表路径,因为我们存储到数据库里面知识一个路径,不是一个文件,我们的文件是要保存到本地的
 */
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]


慕数据017433
浏览 1230回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java