尚好房-后台完结-遇到的一些小问题

不加@ResponseBody 它会报这样的错
Caused by: java.io.FileNotFoundException:
Could not open ServletContext resource [/WEB-INF/templates/houseImage/upload/3/1.html]

因为不加,它就会被viewResolver给解析,拼前缀/WEB-INF/templates/ 拼后缀.html ,拼完了以后它会报 这个路径找不到

@ResponseBody
@RequestMapping("/upload/{houseId}/{type}")
private Result upload(@RequestParam("file") MultipartFile[] files, @PathVariable("houseId") Long houseId,
@PathVariable("type") Integer type) throws IOException {

    if(files.length > 0) {
        for(MultipartFile file : files) {

            String newFileName =  UUID.randomUUID().toString() ;

            QiniuUtils.upload2Qiniu(file.getBytes(),newFileName);


            String url= "http://r9neo7w7o.hn-bkt.clouddn.com/"+ newFileName;

            HouseImage houseImage = new HouseImage();
            houseImage.setHouseId(houseId);
            houseImage.setType(type);
            houseImage.setImageName(file.getOriginalFilename());
            houseImage.setImageUrl(url);

            houseImageService.insert(houseImage);


        }
    }

    return Result.ok();

}

上传业务上的: 上传的文件名字必须保证唯一, 因为 网络上 无数人用的软件上传,如果文件名字不唯一,前面人上传的就被覆盖掉了,或者说自己覆盖了自己的文件

posted @ 2022-04-01 19:35  jiejie0830  阅读(32)  评论(0)    收藏  举报