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中发现了一 ...
随机推荐
- CentOS SSH安全和配置无密码登录
CentOS ssh默认监听端口 22端口,允许root用户ssh登录.server投入生产后很有必要更改默认ssh监听端口和禁止root登录. 步骤1:确认安装有ssh包 [appuser@su17 ...
- 基于struts2的记住账号密码的登录设计
一个简单的基于struts2的登录功能,实现的额外功能有记住账号密码,登录错误提示.这里写上我在设计时的思路流程,希望大家能给点建设性的意见,帮助我改善设计. 登录功能的制作,首先将jsp界面搭建出来 ...
- moviepy音视频开发:audio_fadein、fadeout实现声音淡入淡出
☞ ░ 前往老猿Python博文目录 ░ 一.概述 为了支持一些常规的音频变换处理,moviepy提供了一系列常用的变换函数,开发者可以直接使用这些方法进行变换,这些函数都在moviepy.audio ...
- PyQt(Python+Qt)学习随笔:QTreeView树形视图的itemsExpandable属性
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTreeView树形视图的itemsExpandable属性用于控制视图中用户是否可以通过操作展开 ...
- C# operator 关键字的用法
operator 只要是运算符都能重载 operator 关键字的主要作用是用来重载运算符的,还可以用于类或结构中类型的自定义转换. 下面看个例子 class Feige { //定义两个全局变量 i ...
- webpack项目如何正确打包引入的自定义字体
webpack项目如何正确打包引入的自定义字体 一. 如何在Vue或React项目中使用自定义字体 在开发前端项目时,经常会遇到UI同事希望在项目中使用一个炫酷字体的需求.那么怎么在项目中使用自定义字 ...
- CF1416D Graph and Queries
本题解用于作者加深算法印象,也欢迎各位的阅读. 题目大意 给你一张无向图,并给你两种操作: \(1~v\) :找到当前点 \(v\) 所在的联通块内权值最大的点,输出该点权值并将其权值改为 \(0\) ...
- 【操作系统】页面置换算法(最佳置换算法)(C语言实现)
[操作系统]页面置换算法(最佳置换算法)(C语言实现) (编码水平较菜,写博客也只是为了个人知识的总结和督促自己学习,如果有错误,希望可以指出) 1.页面置换算法: 在地址映射过程中,若在页面中发现所 ...
- HashMap 中 Key 类型的选择
什么对象可以作为HashMap的key值? 从HashMap的语法上来讲,一切对象都可以作为Key值.如:Integer.Long.String.Object等.但是在实际工作中,最常用的使用Stri ...
- 03-flask-视图函数基础
代码 from flask import Flask, request, url_for, jsonify, redirect # 创建Flask对象 app = Flask(__name__) @a ...