春ブーツMVC JSPは、テンプレートとして使用します

テンプレートエンジンとして春のブートデフォルトThymeleaf、JSPファイルと直接デポジットがメインディレクトリ内に通常のアクセスは、JSPファイルを格納し、テンプレートディレクトリに依存関係を追加する必要があるために、新しいフォルダを作成する必要がありますすることはできません。

1. JSPファイルのディレクトリを作成します。

まず、mainディレクトリの作成webapp(任意の名前をすることができます)カタログを、それがプロジェクトの構造のWebリソースディレクトリに追加されます。

プロジェクト構造

2.依存性を追加します。

JSTLとJSPをサポートするためのpom.xmlに依存して追加します。

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

3. MVCの構成

編集application.yml:

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

配置された相対パスプレフィックスJSPファイル(ここではJSPファイル保存されview、ディレクトリ)サフィックス.jsp

4.書き込みコントローラおよびページ

IndexController


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

@Controller
public class IndexController {

    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView index = new ModelAndView("index");
        index.addObject("message", "Hello, Spring Boot!");
        return index;
    }
}

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Index</title>
</head>
<body>
<h1>Spring Boot with JSP</h1>
<h2>${message}</h2>
</body>
</html>

5. Accessページ

アクセスhttp://localhost:8080/

MVC-デモ

おすすめ

転載: www.cnblogs.com/cloudfloating/p/11787222.html