Spring Boot學習總結(2)——Spring Boot整合Jsp
阿新 • • 發佈:2019-01-22
怎麼使用jsp上面起了疑問,查閱了多方資料,找到過其他人的部落格的描述,也找到了spring在github上的給出的例子,看完後稍微改動後成功
整合jsp,於是決定將整合過程記載下來。
無論使用的是那種ide,基本在maven的使用上都是相同的,本文使用的是myeclipse,建立maven web工程,pom中依賴如下:
- <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
- <modelVersion>4.0.0</modelVersion>
- <groupId>cn.com</groupId>
- <artifactId>springboot-Web</artifactId>
- <packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
- <name>springboot-Web Maven Webapp</name>
-
<url>http://maven.apache.org
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.2.5.RELEASE</version>
- <relativePath/>
- </parent>
- <properties>
-
<project.build.sourceEncoding
- <java.version>1.7</java.version>
- <version.spring>3.2.9.RELEASE</version.spring>
- <version.jackson>2.4.4</version.jackson>
- </properties>
- <dependencies>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!--WebJars-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <!--<version>${spring.boot.version}</version>-->
- <configuration>
- <mainClass>cn.com.SpringBootWebApplication</mainClass>
- <layout>ZIP</layout>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>
- repackage
- </goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>spring-snapshots</id>
- <url>http://repo.spring.io/snapshot</url>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- <repository>
- <id>spring-milestones</id>
- <url>http://repo.spring.io/milestone</url>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>spring-snapshots</id>
- <url>http://repo.spring.io/snapshot</url>
- </pluginRepository>
- <pluginRepository>
- <id>spring-milestones</id>
- <url>http://repo.spring.io/milestone</url>
- </pluginRepository>
- </pluginRepositories>
- </project>
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- <scope>provided</scope>
- </dependency>
- spring.view.prefix=/WEB-INF/jsp/
- spring.view.suffix=.jsp
- application.message: Hello Phil
- server.port=8282
似乎不起作用,有了解的可以與本人探討一下。
下面就是controller編寫,具體不再講解,僅貼出程式碼:
- package cn.com.controller;
- import org.springframework.beans.factory.annotation.Value;
-