本文介绍了SpringBoot集成jsp(附源码)+遇到的坑 ,分享给大家
1、大体步骤
(1)创建Maven web project;
(2)在pom.xml文件添加依赖;
(3)配置application.properties支持jsp
(4)编写测试Controller
(5)编写JSP页面
(6)编写启动类App.java
2、新建SpringInitialzr
springBoot关于访问jsp的设置

3、pom文件


org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-tomcat
provided


org.apache.tomcat.embed
tomcat-embed-jasper


org.springframework.boot
spring-boot-starter-test
test


4、application.properties文件

页面默认前缀目录

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

响应页面默认后缀

spring.mvc.view.suffix=.jsp

自定义属性,可以在Controller中读取

application.hello=Hello GOD
5、Controller文件
package com.example;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller

public class HelloController {

// 从 application.properties 中读取配置,如取不到默认值为Hello
@Value(“${application.hello:Hello}”)
private String hello;

@RequestMapping(“/helloJsp”)
public String helloJsp(Map

相关文章: