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中发现了一 ...
随机推荐
- Cys_Control(四) MTabControl
一.查看TabControl原样式 <ControlTemplate TargetType="{x:Type TabControl}"> <Grid x:Name ...
- DRF的ModelSerializer的使用
在views中添加 from django.shortcuts import render # Create your views here. from rest_framework.views im ...
- (八)函数调用为何会发生“Stack Overflow”
一.一次函数调用分析 c代码: // function_example.c #include <stdio.h> int static add(int a, int b) { return ...
- spring java config配置搭建工程资料收集(网文)
https://blog.csdn.net/poorcoder_/article/details/70231779 https://github.com/lovelyCoder/springsecur ...
- 第11.2节 Python 正则表达式支持函数概览
为了大家熟悉re模块匹配文本的处理,本节将概要介绍与此处理有关的几个主要函数,提供了如下主要函数: 以上函数中的部分的三个重要参数说明如下: pattern都是代表匹配规则的模式字符串,string代 ...
- PyQt学习随笔:Qt中tem Views(Model-Based)和Item Widgets(Item-Based)控件的用途和关系
在界面程序开发中,数据的展示主要包括表格.简单列表.树状列表以及纯文本等多种方式,在Qt中将界面表格.简单列表.树状列表称为"表项视图类(item view class)",并提供 ...
- SpringCloud-服务间通信方式
接下来在整个微服务架构中,我们比较关心的就是服务间的服务改如何调用,有哪些调用方式? 总结:在springcloud中服务间调用方式主要是使用 http restful方式进行服务间调用 1. 基于R ...
- 团队作业三——需求改进&系统设计
需求改进&系统设计 一. 需求&原型改进 1. 针对课堂讨论环节老师和其他组的问题及建议,对修改选题及需求进行修改 老师及其他组的同学在课堂讨论时尚未提出问题及修改意见,但是课后我们有 ...
- HTML引入外部字体
HTML5如何引入外部字体 背景 现在我需要 "Montserrat-ExtraLight ExtraLight"类型的字体,但是html的font-family中找不到这个类型的 ...
- Editor.md解决跨域上传的问题
Editor.md解决跨域上传的问题 编辑 editormd\plugins\image-dialog\image-dialog.js 替换以下代码片段 if (settings.crossDomai ...