时间:2023-05-27 03:54:01 | 来源:网站运营
时间:2023-05-27 03:54:01 来源:网站运营
SpringBoot2.x系列教程17--Web开发03之支持jsp:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --></parent><build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins></build>
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- servlet 依赖. --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency></dependencies>
spring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jsp
src/main/
目录下手动创建出一个新的目录webapp/WEB-INF/jsp/
src/main/
目录下创建新的目录webapp/WEB-INF/jsp/
,在jsp目录下面创建一个index.jsp文件.<%@ page contentType="text/html;charset=UTF-8" language="java" %><!DOCTYPE HTML><%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><html><head> <meta charset="UTF-8"> <title>Boot支持JSP!</title></head><body><h2>Hello ${msg}</h2></body></html>
package com.yyg.boot.web;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.GetMapping;/** * Spring Boot中支持jsp功能的实现 */@Controllerpublic class JspController { @GetMapping("/index") public String index(Model model) { model.addAttribute("msg","跟一一哥学习SpringBoot中使用JSP功能!"); //要跳转到的页面视图名称 return "index"; }}
com.yyg.boot
下创建启动类@SpringBootApplicationpublic class JspApplication { //注意:不要直接启动该类,要以spring-boot:run命令方式启动才行,否则404!!! public static void main(String[] args) { SpringApplication.run(JspApplication.class, args); }}
spring-boot:run
命令方式启动!!!关键词:支持,系列,教程