vue附件上传和展示

先从后台拿到需要的数据,包括上传附件的数据以及文本数据

<resultMap id="result" type="cn.itsource.domain.FileKeyin">
     <id column="id" property="id"></id>
     <result column="fileid" property="fileid"></result>
     <result column="filetitle" property="filetitle"></result>
     <result column="filetype_id" property="fiiletype"></result>
     <result column="filesave_id" property="filesave"></result>
     <collection property="uploade" ofType="cn.itsource.domain.FileUploadE"
                 select="selectupload" column="id">
         <result column="url" property="url"></result>
         <result column="name" property="name"></result>
     </collection>
 </resultMap>




 <select id="selectupload" resultType="cn.itsource.domain.FileUploadE">
     select u.id,u.url,u.name from fileupload u left join key_upload ku on u.id=ku.upload_id
     left join filekeyin k on ku.key_id=k.id where k.id=#{id}
 </select>
 <select id="searchByKeyin" resultMap="result">
     select * from filekeyin
 </select>

在这里插入图片描述

jsp

<el-table-column
        align="center"
        label="附件列表"
        width="200px">
    <template slot-scope="scope">
        <el-upload
                class="upload-demo"
        <%--action="https://jsonplaceholder.typicode.com/posts/"--%>
                action="/fileupload/upload"
                ref="upload"
                :data="{uploaddate}"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                multiple
                :limit="5"
                :on-exceed="handleExceed"
                :file-list="fileList.rows[scope.$index].uploade">
            <el-button size="small" type="primary" @click="runupload(scope.$index, scope.row)">点击上传
            </el-button>
            <%--<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>--%>
        </el-upload>
    </template>
</el-table-column>

load() {
    axios.get("/fileupload/page").then((res) => {
        this.fileList=res.data;
        this.fileupload = res.data.rows;
        this.total=res.data.total
       /* this.fileList.push(res.data.rows[0].uploade[0]);*/
       /* this.fileList=res.data.rows[1].uploade;*/

        })
}

controller


@RequestMapping("/upload")
@ResponseBody
public void getUpload(@RequestParam MultipartFile file, @RequestParam String uploaddate, HttpServletRequest req) throws IOException {
    System.err.println(file.getSize() + "===" + uploaddate + file.getContentType());
    System.err.println(file.getContentType().substring(file.getContentType().lastIndexOf("/") + 1));
    System.out.println(file.getOriginalFilename());
    FileUpload upload = new FileUpload();
    //文件大小mb
    double size = file.getSize() / 1024;
    //文件类型
    String type = file.getContentType().substring(file.getContentType().lastIndexOf("/") + 1);
    //文件名字
    String filename = file.getOriginalFilename();
    String exName = FilenameUtils.getExtension(filename);
    String uuid = UUID.randomUUID().toString();
  /*  String newName = uuid + "." + exName;*/
    String newName=file.getOriginalFilename();
    String realPath = req.getServletContext().getRealPath("/upload/file");

    File file2 = new File(realPath, newName);
    File parenFile = file2.getParentFile();
    if (!parenFile.exists()) {
        parenFile.mkdirs();
    }
    file.transferTo(file2);
    upload.setUrl("/upload/file" + newName);
    upload.setFilesize(size);
    upload.setType(type);
    upload.setFileid(Long.parseLong(uploaddate));
    upload.setName(newName);

    service.save(upload);
    Long uploadId = upload.getId();
    key_upload ku = new key_upload();
    ku.setKey_id(Long.parseLong(uploaddate));
    ku.setUpload_id(uploadId);
    service.saveKU(ku);
    System.out.println("success");
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值