SpringBoot支持Jsp視圖

添加依賴:

<!-- springboot tomcat jsp支持開啟-->

<dependency>

<groupId>org.apache.tomcat.embed</groupId>

<artifactId>tomcat-embed-jasper</artifactId>

</dependency>

<!-- jsp中使用jstl標籤支持-->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

Advertisements

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

</dependency>

YML配置:

mvc:

#支持jsp視圖

view:

prefix: /WEB-INF/views/

suffix: .jsp

Jsp一般放在webapp目錄下,SpringBoot默認沒有webapp目錄,需要添加。注意和resources同級

控制器開發:

packagecom.web;

importorg.springframework.stereotype.Controller;

Advertisements

importorg.springframework.web.bind.annotation.RequestMapping;

/**

*提供JSP訪問控制

* Created by yanghl on 2017/11/21.

*/

@RequestMapping("/hello")

@Controller

publicclass JspController {

@RequestMapping("helloJsp")

public String helloJsp(){

return "index";

}

}

注意事項:

針對el表達式,類似${hello}這個對於servlet的版本是有限制的,2.4版本版本以下是不支持的,是無法進行識別的,請注意。

多模塊下JSP的訪問是有問題的,有待確認。

若配置了ContextPath,則前後端的訪問都需要添加Contextpath,否則訪問失敗。

springboot內部對jsp的支持並不是特別理想,而springboot推薦的視圖是Thymeleaf

架構師視頻資料分享鏈接:

data:text/html;charset=UTF-8;base64,

5p625p6E5biI5a2m5Lmg5Lqk5rWB576k5Y+35pivNTc1NzUxODU0Cg==

複製粘貼在網站即可!

Advertisements

你可能會喜歡