SpringBoot与jsp结合
- Idea 创建Spring Boot项目,在File-Project Structure-Modules设置web
2. 文件配置
》application.properties配置
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
#访问相关配置
server.port=8099
server.tomcat.uri-encoding=UTF-8
#项目访问名称,如果不配置直接访问bean就可以
server.servlet.context-path=/sb
server.servlet.jsp.init-parameters.development=true
》pom.xml配置
<groupId>com.wait</groupId>
<artifactId>moment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>moment</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- <scope>provided</scope>-->
</dependency>
<!--dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.wait.moment.MomentApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
》HelloController.java
package com.wait.moment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/hello")
public String gethello(){
return "hello";
}
}
》MomentApplication.java
package com.wait.moment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MomentApplication {
public static void main(String[] args) {
SpringApplication.run(MomentApplication.class, args);
}
}
3.打包war