springboot 入门(二) 整合jsp页面

1.新建springboot工程,默认选择springboot 2.0,添加webapp文件夹并指定web resource


2.修改springboot的配置文件

#指定端口号
server.port=8888
#指定视图解析路径前缀
spring.mvc.view.prefix=/WEB-INF/jsp/
#指定视图解析后缀
spring.mvc.view.suffix=.jsp

3.添加springboot 整合jsp的依赖

<!--添加springboot整合jsp插件-->
<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <!--<scope>provided</scope> 不需要指定scope-->
</dependency>

4.新建controller类,实现jsp页面跳转处理

/**
 * 自定义controller实现自定义jsp页面的跳转
 */
@Controller
public class IndexController {
    @RequestMapping("/page")
    public ModelAndView index(){
        System.out.println("请求进来了...");
        ModelAndView model = new ModelAndView("index");
        model.addObject("time",new Date());
        return model;
    }
}

5.jsp页面及效果

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>jsp页面</title>
</head>
<body>
    <h1>${time }</h1>
</body>
</html>

6.注意

这里有点疑注意,因为springboot有三种启动方式,此处是使用main启动才需要配置整合jsp的依赖,如果是使用mvn spring-boot:run的命令就不需要配置依赖

7.github地址:springboot整合jsp

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值