十一.Spring Boot使用jsp

该博客介绍了Spring Boot项目搭建的步骤,包括修改pom文件、补全项目结构、配置application.properties以及编写Spring Boot启动类,为Spring Boot项目的搭建提供了清晰的指引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.pom文件修改

<artifactId>spring-boot-sample-web-jsp</artifactId>
<!-- 打包方式改成war -->
<packaging>war</packaging>
<!-- 设置jsp支持 -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>
<!-- Provided -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
	<scope>provided</scope>
</dependency>
<!-- 设置jsp支持 end -->

二.补全项目结构

在这里插入图片描述

三.application.properties

#设置支持jsp
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

#关闭默认模板引擎(设置支持jsp)
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=false

四.springBoot启动类

package com.miracle;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication  // 支持jsp 需要继承 SpringBootServletInitializer
public class Springsecurity01Application extends SpringBootServletInitializer {
	// 支持jsp 重写configure方法
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Springsecurity01Application.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(Springsecurity01Application.class, args);
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值