Spring boot 跳轉(zhuǎn)到j(luò)sp頁(yè)面的實(shí)現(xiàn)方法
本人正在學(xué)習(xí)Spring boot,搜索了很多關(guān)于Spring boot 跳轉(zhuǎn)到j(luò)sp頁(yè)面的實(shí)現(xiàn)方法介紹,下面我來(lái)記錄一下,有需要了解的朋友可參考。希望此文章對(duì)各位有所幫助。
@Controller注解
1、application.properties文件中配置
# 配置jsp文件的位置,默認(rèn)位置為: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、啟動(dòng)項(xiàng)目App.Java中的【main】方法啟動(dòng)
4. 訪問(wèn)url,訪問(wèn)到j(luò)sp頁(yè)面:http://localhost:8080/index
@RestController注解
1、application.properties文件中配置
# 配置jsp文件的位置,默認(rèn)位置為: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、啟動(dòng)項(xiàng)目App.java中的【main】方法啟動(dòng)
4. 訪問(wèn)url,訪問(wèn)到j(luò)sp頁(yè)面:http://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
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Java堆內(nèi)存的10個(gè)要點(diǎn)的總結(jié)分析
本篇文章是對(duì)Java堆內(nèi)存的10個(gè)要點(diǎn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05idea統(tǒng)計(jì)代碼行數(shù)Statistic的步驟詳解
這篇文章主要介紹了idea統(tǒng)計(jì)代碼行數(shù)Statistic的步驟詳解,本文通過(guò)使用Statistic插件操作的,通過(guò)圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10Java數(shù)據(jù)結(jié)構(gòu)與算法入門實(shí)例詳解
這篇文章主要介紹了Java數(shù)據(jù)結(jié)構(gòu)與算法入門實(shí)例詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03解決Mybatis查詢方法selectById()主鍵不一致問(wèn)題
這篇文章主要介紹了解決Mybatis查詢方法selectById()主鍵不一致問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10SpringAOP+RabbitMQ+WebSocket實(shí)戰(zhàn)詳解
這篇文章主要介紹了SpringAOP+RabbitMQ+WebSocket實(shí)戰(zhàn)詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11