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中发现了一 ...
随机推荐
- LaTeX中的数学公式之矩阵
矩阵的代码及注释: 显示效果:
- Mongo管理
MongoDB存储引擎 一. WiredTiger引擎 1. MongoDB3.2版本以上,设置为存储引擎. 2. 基于文档级别的并发控制功能(锁机制) (1). 锁级别:文档级别 (2). ...
- 第12.3节 Python math模块导览
math 模块提供对浮点数学的底层C库函数的访问,常用的成员包括: math.ceil(x):返回 x 的上限,即大于或者等于 x 的最小整数 math.floor(x):返回 x 的向下取整,小于或 ...
- PyQt(Python+Qt)学习随笔:QListView的itemAlignment属性
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListView的itemAlignment属性用于控制每个数据项的对齐方式,其类型为枚举类Qt. ...
- 第二章、PyQt5应用构建详细过程介绍
老猿Python博文目录 老猿Python博客地址 一.引言 在上节<第一章.PyQt的简介.安装与配置>介绍了PyQt5及其安装和配置过程,本节将编写一个简单的PyQt5应用,介绍基本的 ...
- 【题解】「P1504」积木城堡
这题是01背包(\(DP\)) 如何判断要拆走那个积木,首先定义一个\(ans\)数组,来存放这对积木能拼成多高的,然后如果\(ans_i = n\)那么就说明这个高度的积木可以. 话不多说,上代码! ...
- Python编码相关
1.#coding=utf-8的作用 作用是这个文件代码的编码格式,如果没有声明代码中不能出现中文字符,包括注释中也不能出现.否则会报错SyntaxError: Non-ASCII character ...
- Angular:使用service进行http请求的简单封装
①使用ng g service services/storage创建一个服务组件 ②在app.module.ts 中引入HttpClientModule模块 ③在app.module.ts 中引入创建 ...
- sqli-labs less8-10(布尔盲注时间盲注)
less-8 布尔盲注 首先利用?id=1' and 1=1 --+和?id=1' and 1=2 --+确定id的类型为单引号''包裹.然后进行盲注. 盲注思路: 破解当前数据库名: and len ...
- Spring Session解决Session共享
1. 分布式Session共享 在分布式集群部署环境下,使用Session存储用户信息,往往出现Session不能共享问题. 例如:服务集群部署后,分为服务A和服务B,当用户登录时负载到服务A ...