首页 > 编程语言 > 详细

springboot整合jsp模板

时间:2018-02-23 16:39:44      阅读:171      评论:0      收藏:0      [点我收藏+]

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页面

springboot整合jsp模板

原文:https://www.cnblogs.com/xujie09/p/8462392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!