【2020-01-04】Springboot2.x整合JSP

参考https://my.oschina.net/mdxlcj/blog/1852916

1.pom.xml引入依赖

    
    
      org.apache.tomcat.embed
      tomcat-embed-jasper
    
    
    
    
        javax.servlet
        javax.servlet-api
    

    
    
        javax.servlet.jsp
        javax.servlet.jsp-api
        2.3.1
    

    
    
        javax.servlet
        jstl
    

2.项目目录结构

增加webapp文件夹,和resources同级,具体见图


springboot整合jsp-1.png

3.application.yml配置

spring:
  mvc:
    view:
      suffix: .jsp
      prefix: /WEB-INF/page/
    

4.创建index.jsp

路径:/webapp/WEB-INF/page/index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


    
        
        
        首页
    
    
        
${message }

5.创建controller

package com.joiant.tgrow.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {
    
    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("message", "jsp测试内容");
        return "index";
    }

}


6.测试

你可能感兴趣的:(【2020-01-04】Springboot2.x整合JSP)