成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

UEditor怎么在SpringBoot中使用

本篇文章為大家展示了UEditor怎么在SpringBoot中使用,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

蘆溪網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,蘆溪網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為蘆溪近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的蘆溪做網(wǎng)站的公司定做!

因為項目使用的springboot框架,而UEditor對于java后端的支持僅僅是給了一個jsp文件。因此,需要對該文件進(jìn)行一下處理,修改為面向springboot的統(tǒng)一controller。

@Controller
@Transactional
@RequestMapping("/static/common/ueditor/jsp")
public class JSPController {
  @RequestMapping("/controller")
  @ResponseBody
  public void getConfigInfo(HttpServletRequest request,HttpServletResponse response){
    response.setContentType("application/json");
    String rootPath = request.getSession().getServletContext()
        .getRealPath("/");
    try {
      String exec = new ActionEnter(request, rootPath).exec();
      PrintWriter writer = response.getWriter();
      writer.write(exec);
      writer.flush();
      writer.close();
    } catch (IOException | JSONException e) {
      e.printStackTrace();
    }
  }

如上所述,該項目即支持來自/static/common/ueditor/jsp/controller的上傳請求了。

前端請求

在前端添加UEditor支持。即:將整個uediotr包進(jìn)行項目引入,并且在使用該控件的地方進(jìn)行js的導(dǎo)入。

項目引入,我的對應(yīng)代碼結(jié)構(gòu)如下:

UEditor怎么在SpringBoot中使用

頁面引入,引入對應(yīng)代碼如下:

<script type="text/javascript" charset="utf-8" th:src="@{/static/common/ueditor/ueditor.config.js}"></script>
  <script type="text/javascript" charset="utf-8" th:src="@{/static/common/ueditor/ueditor.all.js}"></script>

實例化UEditor編輯器即可,下面是我的初始化參數(shù),僅做參考。

//實例化編輯器
  var ue = UE.getEditor(''+id,{
    toolbars: [
      [
        'fontfamily', //字體
        'fontsize', //字號
        'undo', //撤銷
        'redo', //重做
        '|',
        'emotion', //表情
        'forecolor', //字體顏色
        'backcolor', //背景色
        'bold', //加粗
        'underline', //下劃線
        'strikethrough', //刪除線
        '|',
        'justifyleft', //居左對齊
        'justifyright', //居右對齊
        'justifycenter', //居中對齊
        '|',
        'link', //超鏈接
        'unlink', //取消鏈接
        'simpleupload', //單圖上傳
        'insertimage', //多圖上傳
        //'music', //音樂
        //'insertvideo', //視頻
        'removeformat', //清除格式
        'formatmatch', //格式刷
        'source', //源代碼
      ]
    ],
    enableAutoSave:false,
    autoHeightEnabled: true,
    autoFloatEnabled: true,
    initialFrameWidth:width,
    initialFrameHeight:height,
    scaleEnabled:true//滾動條
  });

此時,訪問我們的頁面就會看到富文本框了。

不過,此時會提示我們后臺配置文件出錯,無法實現(xiàn)上傳功能

實現(xiàn)上傳功能

修改config.js文件,對應(yīng)的全局請求路徑。該請求是為了獲取config.json對應(yīng)的配置數(shù)據(jù)??梢栽贑ontroller里面直接返回配置信息或者在controller里面進(jìn)行json文件的讀取。我這里使用的是讀取配置文件的方式,使用UEditor自帶的方法,文章開頭已經(jīng)實現(xiàn),這里貼一下需要修改的請求:

UEditor怎么在SpringBoot中使用

完成以上配置之后,再次加載UEditor的頁面,其中上傳圖片的按鈕即可完成圖片的上傳了。

注意:如果開始調(diào)試模式,加入斷點,測試加載json串的時候。會出現(xiàn)超時錯誤。暫時沒從配置文件里面找到配置字段。所有,這里需要注意,假如一切配置均無問題,但是依然返回后臺配置錯誤的話,可以把斷點全部取消掉試一試。

注意:上傳需要加入上傳組件,此處使用fileuoload

<dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3</version>
    </dependency>

使用servlet實現(xiàn)上傳

/**
 * 嘗試使用servlet來實現(xiàn)UEditor
 *
 * @author OnyWang
 * @create 2018-02-05 2:40
 **/
@WebServlet(name = "UEditorServlet", urlPatterns = "/static/common/ueditor/UEditor")
public class UEditorControllerServlet extends HttpServlet {
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding( "utf-8" );
    response.setHeader("Content-Type" , "text/html");
    PrintWriter out = response.getWriter();
    ServletContext application=this.getServletContext();
    String rootPath = application.getRealPath( "/" );

    String action = request.getParameter("action");
    String result = new ActionEnter( request, rootPath+"WEB-INF/classes" ).exec();
    if( action!=null &&
        (action.equals("listfile") || action.equals("listimage") ) ){
      rootPath = rootPath.replace("\\", "/");
      result = result.replaceAll(rootPath, "/");
    }
    out.write( result );
  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

采用servlet的方式,新建一個注解式的servlet即可。

需要在main方法里面加入@ServletComponentScan注解。

修改ueditor默認(rèn)訪問路徑。

注意:springboot下面,所有的資源文件都是放在classes下面的,所有,對于路徑的處理一定要加倍小心。放在增加路徑web-inf/classes

上述內(nèi)容就是UEditor怎么在SpringBoot中使用,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:UEditor怎么在SpringBoot中使用
URL地址:http://jinyejixie.com/article48/gdghep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、營銷型網(wǎng)站建設(shè)、電子商務(wù)、搜索引擎優(yōu)化、云服務(wù)器、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司
汉川市| 华容县| 天镇县| 封开县| 城固县| 尉犁县| 稻城县| 从化市| 沁阳市| 北票市| 温泉县| 清丰县| 行唐县| 静乐县| 罗田县| 山阴县| 凭祥市| 金平| 绥宁县| 和林格尔县| 阳城县| 老河口市| 阿勒泰市| 苏州市| 五常市| 揭阳市| 中西区| 富源县| 汾阳市| 社会| 巩留县| 余庆县| 新龙县| 荆门市| 阜南县| 舒兰市| 巩留县| 四川省| 开原市| 开阳县| 江阴市|