springboot 整合 jsp

因为spring boot 默认不支持jsp 所以 我们如果使用jsp作为模板引擎的话需要配置一些东西

第一步 新建一个springboot项目

第二部添加依赖

<!-- tomcat支持 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <!--<scope>provided</scope>-->
        </dependency>
        <!-- jstl标签库 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

第三部 添加配置application.properties

spring.mvc.view.prefix= /WEB-INF/jsp/
spring.mvc.view.suffix= .jsp

第四部  修改配置

添加如下配置

ok ,配置到这里就结束了,接下来我们测试一下

写一个controller

package com.jsp.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class contrller {

    @RequestMapping("/")
    public String index(Map<String, Object> model){
        model.put("message", "hello world");
        return "index";
    }
}

 写一个jsp

<%--
  Created by IntelliJ IDEA.
  User: 23108
  Date: 2019/3/2
  Time: 22:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
Message: ${message}
</body>
</html>

 结果

最后附上项目结构

猜你喜欢

转载自www.cnblogs.com/liouzeshuen/p/10463422.html
今日推荐