gradle管理的Springboot使用JSP详解

大家知道现在的springboot默认经不支持jsp了,但是还是可以用的,需要加一些配置。

我使用的springboot是用gradle构造的,现在跟着我一步步来吧!

一,新建一个springBoot项目(自己建也行,咱使用简便的方式)

打开网址  http://start.spring.io/  看到如下画面

        选择Gradle 工程  版本自己选择

         以下是项目名称 自便

然后点击

下载到电脑上,解压缩,然后导入到idea(我是用的是idea)中

二  导入jar包,加配置文件

修改后的  build.gradle

buildscript {
    ext {
        springBootVersion = '1.4.7.RELEASE'
    }
    repositories {
        maven { url "http://172.16.60.188:8081/nexus/content/groups/public" }//私服地址,自己相应修改
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
//打成war包
apply plugin: 'war'

group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    maven { url "http://172.16.60.188:8081/nexus/content/groups/public" }       //私服地址,自己相应修改
} dependencies { compile('org.springframework.boot:spring-boot-starter') testCompile('org.springframework.boot:spring-boot-starter-test') //启动web项目 compile("org.springframework.boot:spring-boot-starter-web") //jsp使用的jar包 compile("javax.servlet:jstl:1.2") compile 'org.springframework.boot:spring-boot-starter-tomcat' compile 'org.apache.tomcat.embed:tomcat-embed-jasper' }

在resources下建立application.yml

server:
  port: 8080
spring:
  mvc:
    view:
      prefix: /WEB-INF/views/
      suffix: .jsp

然后在main目录下建立webapp等目录

右键点击webapp 就可以看见JSP文件了

然后在和你启动类同级的目录下建立你的controller吧!

亲测可用,不行的联系作者,欢迎各位批评指正!

原文地址:https://www.cnblogs.com/xuningchuanblogs/p/7852317.html