微服务 教程
1085个小节阅读:195.8k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
xxxxxxxxxx
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>wangEditor demo</title>
</head>
<body>
<div id="div1">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
<script type="text/javascript" th:src="@{wangEditor.min.js}" src="../static/wangEditor.min.js"></script>
<script type="text/javascript">
const E = window.wangEditor
const editor = new E('#div1')
//设置文件上传的参数名称
editor.config.uploadFileName = 'files'
// 配置 server 接口地址
editor.config.uploadImgServer = '/upload/uploadMoreImage.do'
// 2M
editor.config.uploadImgMaxSize = 2 * 1024 * 1024
editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
// 一次最多上传 5 个图片
editor.config.uploadImgMaxLength = 5
editor.create()
</script>
</body>
</html>
xxxxxxxxxx
"/upload") (
public class UoloadToFastDFSController {
//fastdfs存储节点的客户端对象
private FastFileStorageClient fastFileStorageClient;
"/upload") (
public void uploadMoreImage(MultipartFile[] files){
//判断是否上传图片
if(files != null && files.length != 0 ){
//遍历上传图片
for (MultipartFile multipartFile : files) {
//获取上传文件名
String filename = multipartFile.getOriginalFilename();
//获取最后一个“.”的下标,并获取从这个下标的下一个下标开始后的字符作为文件后缀
String fileSuffix = filename.substring(filename.lastIndexOf(".") + 1);
StorePath storePath = null;
try {
//上传文件
storePath = fastFileStorageClient.uploadFile(multipartFile.getInputStream(), multipartFile.getSize(), fileSuffix, null);
} catch (IOException e) {
e.printStackTrace();
}
//打印返回的文件在存储节点的唯一标识
System.out.println(storePath.getFullPath());
}
}
}
}