springboot中訪問html頁面


springboot中如果想訪問html頁面,不每訪問一個頁面就寫一個Controller,可以統一寫一個公共的controller方法

代碼:

(1)引入hutool工具依賴

  <!-- hutool工具包-->
<dependency>
<groupId>com.xiaoleilu</groupId>
<artifactId>hutool-all</artifactId>
<version>3.3.0</version>
</dependency>

 

(2)公共Controller

import com.xiaoleilu.hutool.util.StrUtil;
//html訪問控制器
/**
* @return
*/
@RequestMapping(value = "/view/**", method = RequestMethod.GET)
public String html(HttpServletRequest request) {
return StrUtil.removePrefix(request.getRequestURI(), request.getContextPath() + "/view");
}

 (3)訪問頁面路徑

如頁面路徑在demo下,配置文件中servlet.context-path: /test

 

 

則lhttp://localhost:8081/test/view/demo/...../XXX.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM