springboot 支持 jsp 的写法(分别使用 maven 和 gradle 作为构建工具)

下面记录了使用了 gradle 作为构建工具的实现

1、实现了基本的 springboot 的 HelloWorld,可以参考:
http://projects.spring.io/spring-boot/

这时候,视图返回的是一个 json。我们需要让 springboot 也支持返回 jsp。

2、加入运行时依赖

runtime ("org.apache.tomcat.embed:tomcat-embed-jasper")

3、加入插件 springboot 的配置

apply plugin: 'spring-boot'

要能应用该插件,还须要配置

buildscript {
    repositories {
        maven { url "https://repo.spring.io/libs-release" }
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.RELEASE")
    }
}

对于该配置的解释,可以参考:http://www.tuicool.com/articles/rUfEBrr

配置以后,你就可以在自己的 gradle 面板上看到:
这里写图片描述

3、在 application.properties 文件中写上

# 配置启动端口号
server.port=9090
# 配置返回视图的前缀和后缀
spring.mvc.view.prefix=/WEB-INF/app/jsp/
spring.mvc.view.suffix=.jsp

4、容器启动类

@SpringBootApplication
public class Application {


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

启动项目可以使用以下两种方式

1、使用命令行

gradle bootRun

2、或者运行主方法

然后我们在浏览器中输入

http://localhost:9090/hello/book

就可以看到视图和对应的模型返回了。


以下是使用 maven 作为构建工具的做法:

1 先看到这篇文章

spring-boot 添加JSP页面功能 - 记录分享每一点进步和成长 - 博客频道 - CSDN.NET
http://blog.csdn.net/lifuxiangcaohui/article/details/47060231

2 github 官网上 Spring 的例子

spring-boot/spring-boot-samples/spring-boot-sample-web-jsp at v1.2.7.RELEASE · spring-projects/spring-boot · GitHub
https://github.com/spring-projects/spring-boot/tree/v1.2.7.RELEASE/spring-boot-samples/spring-boot-sample-web-jsp

已经初步完成了,就差最后一步,没有实现。
思路:把上面 github 的代码下载下来研究一下就可以了。

3 最后解决问题看到这篇文章

http://bbs.csdn.net/topics/390873340

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值