UEditor簡(jiǎn)介
UEditor是由百度web前端研發(fā)部開(kāi)發(fā)所見(jiàn)即所得富文本web編輯器畸冲,具有輕量馒索,可定制姻灶,注重用戶體驗(yàn)等特點(diǎn),開(kāi)源基于MIT協(xié)議赶站,允許自由使用和修改代碼
官網(wǎng):https://ueditor.baidu.com/
UEditor分類
UEeditor(官網(wǎng)上的開(kāi)發(fā)版)
Github地址:https://github.com/fex-team/ueditor
官方文檔地址:http://fex.baidu.com/ueditor/
另一個(gè)是UMeditor(mini版)
Github地址:https://github.com/fex-team/umeditor
UMeditor幔虏,簡(jiǎn)稱UM,是ueditor的簡(jiǎn)版贝椿。是為滿足廣大門戶網(wǎng)站對(duì)于簡(jiǎn)單發(fā)帖框和回復(fù)框的需求想括,專門定制的在線富文本編輯器。
UEditor/UMeditor主要特點(diǎn)
1.輕量: 主文件的代碼量為139k烙博。
2.加載速度更快: 放棄了使用傳統(tǒng)的iframe模式瑟蜈,采用了div的加載方式,以達(dá)到更快的加載速度和零加載失敗率习勤。
3.可定制: 配置項(xiàng)完善,可定制程度高焙格。
4.可擴(kuò)展: 代碼層次拆分清晰图毕,功能以插件形式掛接,可靈活定制需要的功能眷唉。
5.多后臺(tái)支持: 支持php予颤、asp囤官、jsp、.net四種后臺(tái)部署代碼
6.功能豐富: 支持插入公式蛤虐、粘貼QQ截屏党饮、拖放上傳圖片、插入地圖驳庭、草稿箱功能
與SpringBoot進(jìn)行集成
由于整合的是前端框架刑顺,所以u(píng)editor官方并沒(méi)有jar包傳到maven倉(cāng)庫(kù)
引入ueditor
包的源碼地址:
https://github.com/weiangongsi/ueditor-spring-boot-starter
<dependency>
<groupId>com.dcssn</groupId>
<artifactId>ueditor-spring-boot-starter</artifactId>
<version>0.0.1</version>
</dependency>
<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>
下載UEditor源碼
UEditor/UMeditor源碼下載地址https://ueditor.baidu.com/website/download.html
Java
下載JSP
版本的就可以了,下載解壓后你會(huì)發(fā)現(xiàn)有html
,css
,js
,圖片等靜態(tài)資源饲常,直接在static
靜態(tài)資源目錄下創(chuàng)建個(gè)ueditor
目錄蹲堂,然后把解壓出來(lái)的靜態(tài)資源都放進(jìn)去就可以了
這里說(shuō)下jsp目錄
jsp
里面包含了Java
集成ueditor
會(huì)用到的一些Jar
包還有一個(gè)JSP
頁(yè)面,這里用thymeleaf
模板代替就不需要JSP
了贝淤,由于引入了第三方ueditor
依賴柒竞。所以可以把lib
文件夾和jsp
頁(yè)面都刪掉
重點(diǎn)說(shuō)明
要重點(diǎn)注意config.json
和ueditor.config.js
兩個(gè)文件
config.json
圖片訪問(wèn)路徑前綴imageUrlPrefix
、視頻訪問(wèn)路徑前綴videoUrlPrefix
播聪、文件訪問(wèn)路徑前綴fileUrlPrefix
不要賦值朽基,會(huì)影響回顯,其余參數(shù)可以按照百度文檔修改
ueditor.config.js
將serverUrl
改為yml
配置文件中ue.server-url
的值
yml
配置文件如下
spring:
servlet:
multipart:
max-file-size: 100MB
ue:
config-file: static/ueditor/jsp/config.json
server-url: /ueditor.do
url-prefix: /file
ue.url-prefix= /file
用于回顯圖片离陶,不設(shè)置的話后顯示不出上傳的圖片
Spring
上傳文件默認(rèn)最大1MB稼虎,上傳文件大小會(huì)先被Spring
限制,config.json
文件大小限制要小于Spring
的設(shè)置枕磁,可以將Spring
的限制設(shè)大點(diǎn)
編寫controller和thymeleaf頁(yè)面
@GetMapping("/")
public String index() {
return "ue";
}
主要用來(lái)頁(yè)面跳轉(zhuǎn)渡蜻,別忘了在類上加個(gè)@Controller
注解
<!DOCTYPE html>
<html lang="UTF-8" xmlns:th="http://www.springframework.org/schema/jdbc">
<head>
<meta charset="UTF-8"/>
<title>ueditor</title>
<style>
#editor {
width: 1024px;
height: 500px;
}
</style>
</head>
<body>
<div id="editor" type="text/plain"></div>
<script th:src="@{/ueditor/ueditor.config.js}"></script>
<script th:src="@{/ueditor/ueditor.all.min.js}"></script>
<script th:src="@{/ueditor/lang/zh-cn/zh-cn.js}"></script>
<script>
UE.getEditor('editor');
</script>
</body>
</html>
UE.getEditor('editor')
在ueditor.all.js
中,用于得到UEditor編輯器實(shí)例
測(cè)試啟動(dòng)
訪問(wèn)http://localhost:8080/
成功看到UEditor
編輯器界面說(shuō)明集成成功
文件存儲(chǔ)路徑
每次上傳文件计济,圖片茸苇,或者視頻,都會(huì)在項(xiàng)目對(duì)應(yīng)的磁盤下生成ueditor
文件夾
存儲(chǔ)格式路徑其實(shí)在config.json
中都可以設(shè)置的沦寂,在config.json
中搜索PathFormat
關(guān)鍵字就可以找到各種文件的路徑設(shè)置
Window
比如說(shuō)你的項(xiàng)目在D盤学密,有上傳文件的話就會(huì)在D盤自動(dòng)生成ueditor文件夾用于本地存儲(chǔ)
Linux服務(wù)器
ueditor
文件夾就會(huì)在根路徑生成