springboot整合jsp模板

在使用springboot框架里使用jsp的时候,页面模板使用jsp在pom.xnl中需要引入相关的依赖,否则在controller中无法返回到指定页面

〇、搭建springboot框架

一、添加jsp相关的依赖如下:

<!-- servlet 依赖. -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<scope>provided</scope>
</dependency>
<!-- JSTL 依赖. -->
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat 的支持. -->
<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-tomcat</artifactId>
		<scope>provided</scope>
</dependency>
<!-- -jasper依赖.(暂时不知道干啥的) -->
<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
	<scope>provided</scope>
</dependency>

二、配置文件

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

三、controller

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import com.xujie.service.CountService;

@Controller
public class CountController {
	
	@Autowired
	private CountService countService;
	
	//跳转页面
	@GetMapping("/index")
	public String goIndex() {
		return "index";
	}
}

四、在/WEB-INF/jsp下编写index.jsp页面

 posted on 2018-02-23 15:54  徐杰  阅读(231)  评论(0编辑  收藏  举报