Spring boot 跳轉到jsp頁面的實現(xiàn)方法
本人正在學習Spring boot,搜索了很多關于Spring boot 跳轉到jsp頁面的實現(xiàn)方法介紹,下面我來記錄一下,有需要了解的朋友可參考。希望此文章對各位有所幫助。
@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頁面:http://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頁面: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
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
idea統(tǒng)計代碼行數(shù)Statistic的步驟詳解
這篇文章主要介紹了idea統(tǒng)計代碼行數(shù)Statistic的步驟詳解,本文通過使用Statistic插件操作的,通過圖文實例相結合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10
解決Mybatis查詢方法selectById()主鍵不一致問題
這篇文章主要介紹了解決Mybatis查詢方法selectById()主鍵不一致問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
SpringAOP+RabbitMQ+WebSocket實戰(zhàn)詳解
這篇文章主要介紹了SpringAOP+RabbitMQ+WebSocket實戰(zhàn)詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11

