springclud中附件上传
package org.springblade.desk.controller; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.desk.entity.OaAttachment;
import org.springblade.desk.service.IOaAttachmentService;
import org.springblade.desk.vo.OaAttachmentVO;
import org.springblade.desk.wrapper.OaAttachmentWrapper;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore; import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID; /**
* 控制器
*
* @author Sxx
*/
//@ApiIgnore
@RestController
@RequestMapping("/oa/attachment")
@AllArgsConstructor
@Api(value = "文件", tags = "文件")
public class OaAttachmentController extends BladeController implements CacheNames { private IOaAttachmentService oaAttachmentService; /**
* 上传文件
* @param files 文件
*/
@PostMapping("upload")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "上传文件", notes = "传入文件")
public R<List<OaAttachment>> upload(@RequestParam List<MultipartFile> files) {
List<OaAttachment> list = new ArrayList<OaAttachment>();
//String dirPath = getRequest().getServletContext().getRealPath("/") +"uploadFile/";
String dirPath = "E:/oaAttachment/uploadFile/" ;
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdir();
}
files.forEach(file -> {
try {
String fileName = file.getOriginalFilename();
String fileType = fileName.substring(fileName.indexOf("."));
String filePath = UUID.randomUUID().toString() +fileType;
File newFile = new File(dirPath, filePath);
FileCopyUtils.copy(file.getInputStream(),Files.newOutputStream(newFile.toPath()));
OaAttachment attachment = new OaAttachment();
attachment.setName(fileName);
attachment.setType(fileType);
attachment.setUrl("uploadFile/"+filePath);
attachment.setAttachmentSize(file.getSize());
oaAttachmentService.save(attachment);
list.add(attachment);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
});
return R.data(list);
} /**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入entity")
public R<OaAttachmentVO> detail(OaAttachment entity) {
OaAttachment detail = oaAttachmentService.getOne(Condition.getQueryWrapper(entity));
return R.data(OaAttachmentWrapper.build().entityVO(detail));
} /**
* 列表分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "列表分页", notes = "传入entity")
public R<IPage<OaAttachmentVO>> list(@ApiIgnore @RequestParam Map<String, Object> entity, Query query) {
IPage<OaAttachment> pages = oaAttachmentService.page(Condition.getPage(query), Condition.getQueryWrapper(entity, OaAttachment.class));
return R.data(OaAttachmentWrapper.build().pageVO(pages));
} /**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "新增", notes = "传入entity")
public R save(@RequestBody OaAttachment entity) {
return R.status(oaAttachmentService.save(entity));
} /**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "修改", notes = "传入entity")
public R update(@RequestBody OaAttachment entity) {
return R.status(oaAttachmentService.updateById(entity));
} /**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@ApiOperation(value = "新增或修改", notes = "传入entity")
public R submit(@RequestBody OaAttachment entity) {
return R.status(oaAttachmentService.saveOrUpdate(entity));
} /**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "逻辑删除", notes = "传入entity")
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
boolean temp = oaAttachmentService.deleteLogic(Func.toLongList(ids));
return R.status(temp);
} }
//=======实现类
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.desk.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
/**
* OA附件实体类
*
* @author Sxx
*/
@Data
@TableName("oa_attachment")
@EqualsAndHashCode(callSuper = true)
public class OaAttachment extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* businessId
*/
@JsonSerialize(
using = ToStringSerializer.class
)
private Long businessId;
/**
* processInstanceId
*/
private String processInstanceId;
/**
* 名称
*/
private String name;
/**
* 地址
*/
private String url;
/**
* 类型
*/
private String type;
/**
* 大小
*/
private long attachmentSize;
}
//==== util
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Files;
import org.springframework.lang.Nullable;
public abstract class FileCopyUtils {
public static final int BUFFER_SIZE = 4096;
public FileCopyUtils() {
}
public static int copy(File in, File out) throws IOException {
Assert.notNull(in, "No input File specified");
Assert.notNull(out, "No output File specified");
return copy(Files.newInputStream(in.toPath()), Files.newOutputStream(out.toPath()));
}
public static void copy(byte[] in, File out) throws IOException {
Assert.notNull(in, "No input byte array specified");
Assert.notNull(out, "No output File specified");
copy((InputStream)(new ByteArrayInputStream(in)), (OutputStream)Files.newOutputStream(out.toPath()));
}
public static byte[] copyToByteArray(File in) throws IOException {
Assert.notNull(in, "No input File specified");
return copyToByteArray(Files.newInputStream(in.toPath()));
}
public static int copy(InputStream in, OutputStream out) throws IOException {
Assert.notNull(in, "No InputStream specified");
Assert.notNull(out, "No OutputStream specified");
int var2;
try {
var2 = StreamUtils.copy(in, out);
} finally {
try {
in.close();
} catch (IOException var12) {
}
try {
out.close();
} catch (IOException var11) {
}
}
return var2;
}
public static void copy(byte[] in, OutputStream out) throws IOException {
Assert.notNull(in, "No input byte array specified");
Assert.notNull(out, "No OutputStream specified");
try {
out.write(in);
} finally {
try {
out.close();
} catch (IOException var8) {
}
}
}
public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException {
if (in == null) {
return new byte[0];
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
copy((InputStream)in, (OutputStream)out);
return out.toByteArray();
}
}
public static int copy(Reader in, Writer out) throws IOException {
Assert.notNull(in, "No Reader specified");
Assert.notNull(out, "No Writer specified");
try {
int byteCount = 0;
char[] buffer = new char[4096];
int bytesRead;
for(boolean var4 = true; (bytesRead = in.read(buffer)) != -1; byteCount += bytesRead) {
out.write(buffer, 0, bytesRead);
}
out.flush();
int var5 = byteCount;
return var5;
} finally {
try {
in.close();
} catch (IOException var15) {
}
try {
out.close();
} catch (IOException var14) {
}
}
}
public static void copy(String in, Writer out) throws IOException {
Assert.notNull(in, "No input String specified");
Assert.notNull(out, "No Writer specified");
try {
out.write(in);
} finally {
try {
out.close();
} catch (IOException var8) {
}
}
}
public static String copyToString(@Nullable Reader in) throws IOException {
if (in == null) {
return "";
} else {
StringWriter out = new StringWriter();
copy((Reader)in, (Writer)out);
return out.toString();
}
}
}
// util======
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import org.springframework.lang.Nullable;
public abstract class StreamUtils {
public static final int BUFFER_SIZE = 4096;
private static final byte[] EMPTY_CONTENT = new byte[0];
public StreamUtils() {
}
public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException {
if (in == null) {
return new byte[0];
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
copy((InputStream)in, out);
return out.toByteArray();
}
}
public static String copyToString(@Nullable InputStream in, Charset charset) throws IOException {
if (in == null) {
return "";
} else {
StringBuilder out = new StringBuilder();
InputStreamReader reader = new InputStreamReader(in, charset);
char[] buffer = new char[4096];
boolean var5 = true;
int bytesRead;
while((bytesRead = reader.read(buffer)) != -1) {
out.append(buffer, 0, bytesRead);
}
return out.toString();
}
}
public static void copy(byte[] in, OutputStream out) throws IOException {
Assert.notNull(in, "No input byte array specified");
Assert.notNull(out, "No OutputStream specified");
out.write(in);
}
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
Assert.notNull(in, "No input String specified");
Assert.notNull(charset, "No charset specified");
Assert.notNull(out, "No OutputStream specified");
Writer writer = new OutputStreamWriter(out, charset);
writer.write(in);
writer.flush();
}
public static int copy(InputStream in, OutputStream out) throws IOException {
Assert.notNull(in, "No InputStream specified");
Assert.notNull(out, "No OutputStream specified");
int byteCount = 0;
byte[] buffer = new byte[4096];
int bytesRead;
for(boolean var4 = true; (bytesRead = in.read(buffer)) != -1; byteCount += bytesRead) {
out.write(buffer, 0, bytesRead);
}
out.flush();
return byteCount;
}
public static long copyRange(InputStream in, OutputStream out, long start, long end) throws IOException {
Assert.notNull(in, "No InputStream specified");
Assert.notNull(out, "No OutputStream specified");
long skipped = in.skip(start);
if (skipped < start) {
throw new IOException("Skipped only " + skipped + " bytes out of " + start + " required");
} else {
long bytesToCopy = end - start + 1L;
byte[] buffer = new byte[4096];
while(bytesToCopy > 0L) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) {
break;
}
if ((long)bytesRead <= bytesToCopy) {
out.write(buffer, 0, bytesRead);
bytesToCopy -= (long)bytesRead;
} else {
out.write(buffer, 0, (int)bytesToCopy);
bytesToCopy = 0L;
}
}
return end - start + 1L - bytesToCopy;
}
}
public static int drain(InputStream in) throws IOException {
Assert.notNull(in, "No InputStream specified");
byte[] buffer = new byte[4096];
int bytesRead = true;
int byteCount;
int bytesRead;
for(byteCount = 0; (bytesRead = in.read(buffer)) != -1; byteCount += bytesRead) {
}
return byteCount;
}
public static InputStream emptyInput() {
return new ByteArrayInputStream(EMPTY_CONTENT);
}
public static InputStream nonClosing(InputStream in) {
Assert.notNull(in, "No InputStream specified");
return new StreamUtils.NonClosingInputStream(in);
}
public static OutputStream nonClosing(OutputStream out) {
Assert.notNull(out, "No OutputStream specified");
return new StreamUtils.NonClosingOutputStream(out);
}
private static class NonClosingOutputStream extends FilterOutputStream {
public NonClosingOutputStream(OutputStream out) {
super(out);
}
public void write(byte[] b, int off, int let) throws IOException {
this.out.write(b, off, let);
}
public void close() throws IOException {
}
}
private static class NonClosingInputStream extends FilterInputStream {
public NonClosingInputStream(InputStream in) {
super(in);
}
public void close() throws IOException {
}
}
}
springclud中附件上传的更多相关文章
- tp中附件上传文件,表单提交
public function tianjia(){ $goods=D('Goods'); if(!empty($_POST)){ if($_FILES['f_goods_image']['error ...
- playframework中多附件上传注意事项
playframework中多附件上传注意事项 2013年09月24日 play 暂无评论 //play版本问题 经确认,1.0.3.2版本下控制器中方法参数 List<File> fi ...
- asp.net结合uploadify实现多附件上传
1.说明 uploadify是一款优秀jQuery插件,主要功能是批量上传文件.大多数同学对多附件上传感到棘手,现将asp.net结合uploadfiy如何实现批量上传附件给大家讲解一下,有什么不对的 ...
- Discuz!X2大附件上传插件-Xproer.HttpUploader6
插件代码(github):https://github.com/1269085759/up6-discuz 插件代码(coding):https://coding.net/u/xproer/p/up6 ...
- 基于MVC4+EasyUI的Web开发框架形成之旅--附件上传组件uploadify的使用
大概一年前,我还在用Asp.NET开发一些行业管理系统的时候,就曾经使用这个组件作为文件的上传操作,在随笔<Web开发中的文件上传组件uploadify的使用>中可以看到,Asp.NET中 ...
- 百度在线编辑器UEditor(v1.3.6) .net环境下详细配置教程之更改图片和附件上传路径
本文是接上一篇博客,如果有疑问请先阅读上一篇:百度在线编辑器UEditor(v1.3.6) .net环境下详细配置教程 默认UEditor上传图片的路径是,编辑器包目录里面的net目录下 下面就演示如 ...
- 使用plupload做一个类似qq邮箱附件上传的效果
公司项目中使用的框架是springmvc+hibernate+spring,目前需要做一个类似qq邮箱附件上传的功能,暂时只是上传小类型的附件 处理过程和解决方案都需要添加附件,处理过程和解决方案都可 ...
- Dynamic CRM 2013学习笔记(十三)附件上传 / 上传附件
上传附件可能是CRM里比较常用的一个需求了,本文将介绍如何在CRM里实现附件的上传.显示及下载.包括以下几个步骤: 附件上传的web页面 附件显示及下载的附件实体 调用上传web页面的JS文件 实体上 ...
- dedecms 5.7文章编辑器附件上传图标不显示
我最近发现在使用dedecms 5.7文章编辑器附件上传图标不显示了,以前是没有问题的,这个更新系统就出来问题了,下面我来给大家分享此问题解决办法. 问题bug:在dedecms 5.7中发现了一 ...
随机推荐
- pixi.js持续渲染页面
Pixi是一个超快的2D渲染引擎,通过Javascript和Html技术创建动画或管理交互式图像,从而制作游戏或应用. 项目地址:https://github.com/pixijs/pixi.js A ...
- LeetCode 041 First Missing Positive
题目要求:First Missing Positive Given an unsorted integer array, find the first missing positive integer ...
- Python【Python基础】
python的使用 1.python的两个版本:python2.0与python3.0.这两个版本的区别在于python3是不向下兼容python2的组件和扩展的,但是在python2.6和2.7的两 ...
- 分享篇:聊一聊 15.5K 的 FileSaver,是如何工作的?
聊一聊 15.5K 的 FileSaver,是如何工作的? FileSaver.js 是在客户端保存文件的解决方案,非常适合在客户端上生成文件的 Web 应用程序.它简单易用且兼容大多数浏览器,被作为 ...
- moviepy音视频剪辑:headblur函数遇到的TypeError: integer argument expected, got float错误的解决方案
运行环境如下: python版本:3.7 opencv-python版本:4.2.0.34 numpy版本:1.19.0 错误信息: 在调用moviepy1.03版本的headblur函数执行人脸跟踪 ...
- 老猿学5G:融合计费场景的离线计费会话的Nchf_OfflineOnlyCharging_Create创建操作
☞ ░ 前往老猿Python博文目录 ░ 一.Nchf_OfflineOnlyCharging_Create消息交互流程 Nchf_OfflineOnlyCharging_Create服务化操作请求是 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中主窗口对象documentMode属性
documentMode属性表示当前主窗口是否启用文档模式,如果是则主窗口的选项卡部件会以适合操作文档的模式呈现,这类似于macOS上的文档模式. 设置此属性时,界面上不会呈现选项卡部件框架.此模式当 ...
- 【学习笔记】动态 dp 入门简易教程
序列 dp 引入:最大子段和 给定一个数列 \(a_1, a_2, \cdots, a_n\)(可能为负),求 \(\max\limits_{1\le l\le r\le n}\left\{\sum_ ...
- Power BI八年回望记
本人从事BI,数据仓库领域相关工作15个年头,这15年目睹了这个方向从火爆到逐渐被大数据领域不断吞食.中间零散关注Power BI好长时间,也算目睹了它的成长. 那天在网络上搜索power bi,无意 ...
- MySQL技术内幕InnoDB存储引擎(四)——表相关
表是什么? 就是关于特定实体地数据集合,是关系型数据库模型地核心. 索引组织表 什么是索引组织表? 表中数据都是根据主键的顺序组织存放的,这种存储方式就是索引组织表.就是存储在一个索引结构中的表. 也 ...