基于SpringBoot的SSM框基础版 - 之jsp支持扩展
SSM框架基础版说明见:https://my.oschina.net/gmarshal/blog/1806267
SSM框架基础版源码见:https://gitee.com/gmarshal/framework-ssm-springboot-simple
下面介绍基于SSM框架基础版本的jsp扩展支持
pom.xml
新增jsp支持依赖
<!--如果启动出错,则删除掉provided-->
<!--jsp支持-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<!--启用jstl支持-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
build中新增plugin
<!-- 忽略无web.xml警告 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
build中新增resources
<resources>
<!-- 打包时将jsp文件拷贝到META-INF目录下 -->
<resource>
<!-- 指定resources插件处理哪个目录下的资源文件 -->
<directory>src/main/webapp</directory>
<!--注意此次必须要放在此目录下才能被访问到 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
启动类
需要继承 SpringBootServletInitializer
并重写 configure
方法
package com.foruo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
/**
* 程序启动类
* @author GaoYuan
* @date 2018/5/3 下午3:47
*/
@SpringBootApplication
@EnableAutoConfiguration
public class BaseStartApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(BaseStartApplication.class);
}
public static void main(String[] args){
SpringApplication.run(BaseStartApplication.class,args);
}
}
配置文件
application.yml 添加相关配置
spring
mvc:
view:
prefix: /WEB-INF/view/
suffix: .jsp
编写MVC
主要修改的是controller 与新增jsp
- @RestController 需要更改成 @Controller
- controller方法返回值需要更改为String
启动项目测试
http://localhost:8080/demo/to?id=1
码云:https://gitee.com/gmarshal/framework-ssm-jsp-springboot-simple