springboot 集成 jsp 啓動三步驟及其注意事項

  • 公司一直是前後端分離項目,今天打開了一個集中式項目,就對集中式項目做了一下了解!下面就是對jsp項目如何啓動及其相關介紹!

一、首先添加依賴,因爲springboot默認是不支持jsp的,所以要添加springboot支持jsp的依賴。

 <!--springboot支持jsp依賴-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

二、其次,我們要有一個web環境,需要添加web依賴。

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

三、使用插件啓動項目
在這裏插入圖片描述
步驟已經標出

另外說一下其他的相關介紹,在application.yml中

spring:
  mvc:
    view:
      prefix: /pages/
      suffix: .jsp

prefix指跳轉到的jsp的所在的文件夾
suffix指跳轉到的jsp的後綴

在controller中

@Controller     //這種情況下尋找名字爲success的頁面
@RequestMapping("/product")
public class ProductController {

    @Secured("ROLE_PRODUCT")      //擁有該角色  可以訪問
    @RequestMapping("/findAll")
    public String findAll(){
        return "product-list";
    }
}

切記註解不要使用@RestController,因爲使用該註解,返回的是json串,就不會跳轉到響應的jsp頁面。另外,因爲我是返回了product-list,那麼根據application.yml的相關設定,意思是執行該controller中的findAll方法後,將會自動跳轉到pages的文件夾下的product-list.jsp頁面

這輩子堅持與不堅持都不可怕,怕的是獨自走在堅持的道路上!!!

歡迎加入技術羣聊!!!
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章