springboot:web项目支持jsp作为视图输出

2017-05-05  本文已影响1029人  无至

构建springboot项目


修改pom.xml支持jsp


<!-- spring boot tomcat jsp 支持开启 -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- servlet支持开启 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- jstl 支持开启 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

增加jsp文件目录、文件、控制器


<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>

package com.example.controller;

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

@Controller
public class IndexController {

    @GetMapping("/")
    public String index (Model model) {
        model.addAttribute("message", "this is index jsp page");
        return "index";
    }
}
server:
  port: 80
  
spring:
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp

结束

上一篇下一篇

猜你喜欢

热点阅读