這篇文章主要介紹了Spring boot 跳到jsp頁面的實作方法,小編覺得挺好的,現在分享給大家,也給大家做個參考。一起跟著小編過來看看吧
本人正在學習Spring boot,搜尋了很多關於Spring boot 跳到jsp頁面的實作方法介紹,下面我來記錄一下,有需要了解的朋友可參考。希望這篇文章對各位有幫助。
@Controller註解
1、application.properties檔案中設定
# 配置jsp文件的位置,默认位置为:src/main/webapp spring.mvc.view.prefix=/pages/ # 配置jsp文件的后缀 spring.mvc.view.suffix=.jsp
2、Controller檔案中設定
import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class UserController { @RequestMapping(value = "/index",method = RequestMethod.GET) public String toIndex(){ return "index"; } }
3、啟動專案App.Java中的【main】方法啟動
4. 存取url,造訪到jsp頁面:localhost:8080/index
#@RestController註解
1、application.properties檔案中設定
# 配置jsp文件的位置,默认位置为:src/main/webapp spring.mvc.view.prefix=/pages/ # 配置jsp文件的后缀 spring.mvc.view.suffix=.jsp
2、RestController檔案中設定
import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.RestController; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @RestController public class UserController { @RequestMapping(value = "/index",method = RequestMethod.GET) public String toIndex(){ ModelAndView mv = new ModelAndView("index"); return mv; } }
3、啟動專案App.java中的【main】方法啟動
4. 存取url,造訪到jsp頁面:localhost:8080/index
注意:application.properties中spring.mvc.view.prefix和spring.mvc.view.prefix屬性,在spring-boot 老版本中和新版本中不一樣:
老版本中用:
spring.view.prefix=/pages/ spring.view.suffix=.jsp
新版本中用:
spring.mvc.view.prefix=/pages/ spring.mvc.view.suffix=.jsp
【相關推薦】
1. Java免費影片教學
3. JFinal線上手冊
以上是java實作jsp頁面跳轉的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文討論了使用Maven和Gradle進行Java項目管理,構建自動化和依賴性解決方案,以比較其方法和優化策略。

本文使用Maven和Gradle之類的工具討論了具有適當的版本控制和依賴關係管理的自定義Java庫(JAR文件)的創建和使用。

本文討論了使用咖啡因和Guava緩存在Java中實施多層緩存以提高應用程序性能。它涵蓋設置,集成和績效優勢,以及配置和驅逐政策管理最佳PRA

本文討論了使用JPA進行對象相關映射,並具有高級功能,例如緩存和懶惰加載。它涵蓋了設置,實體映射和優化性能的最佳實踐,同時突出潛在的陷阱。[159個字符]

Java的類上載涉及使用帶有引導,擴展程序和應用程序類負載器的分層系統加載,鏈接和初始化類。父代授權模型確保首先加載核心類別,從而影響自定義類LOA


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Dreamweaver CS6
視覺化網頁開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能