springmvc+jsp轉spring boot結構 前後端分離
1、前端
1.1、頁面遷移到resourecs,這個位置可以自己定義
1.2、加入插件
[html] view plain copy
<build>
<plugins>
- <!-- spring dev -->
<plugin>
<groupId>
org.springframework.boot</groupId>
<artifactId>
spring-boot-maven-plugin</artifactId>
<version>
1.4.2.RELEASE</version>
<configuration>
<mainClass>
test.Application
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage</goal>
</goals>
</execution>
</executions>
<dependencies>
- <!-- spring熱部署 -->
<dependency>
<groupId>
org.springframework</groupId>
<artifactId>
springloaded</artifactId>
<version>
1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
- <!-- 忽略無web.xml警告 -->
<plugin>
<groupId>
org.apache.maven.plugins</groupId>
<artifactId>
maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>
false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<resources>
- <!-- 打包時將jsp文件拷貝到META-INF目錄下 -->
<resource>
- <!-- 指定resources插件處理哪個目錄下的資源文件 -->
<directory>
src/main/resources/META-INF/resources/WEB-INF</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>
</build>
注意:需要制定文檔位置和打包的文件位置
2、後端
2.1、依賴,包括前端、jsp、springboot的依賴
[html] view plain copy
<dependencies>
<dependency>
<groupId>
com.example</groupId>
<artifactId>
demo-spring-ui</artifactId>
<version>
0.0.1-SNAPSHOT</version>
</dependency>
- <!--
<dependency>
<groupId>
org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-thymeleaf</artifactId>
</dependency>
-->
<dependency>
<groupId>
org.springframework.boot</groupId>
<artifactId>
spring-boot-starter-web</artifactId>
</dependency>
- <!-- servlet依賴. -->
<dependency>
<groupId>
javax.servlet</groupId>
<artifactId>
javax.servlet-api</artifactId>
<scope>
provided</scope>
</dependency>
- <!-- JSTL(JSP Standard TagLibrary,JSP標準標籤庫)是一個不斷完善的開放源代碼的JSP標籤庫,是由apache的jakarta小組來維護的。JSTL只能運行在支持JSP1.2和Servlet2.3規範的容器上,如tomcat
- 4.x。在JSP2.0中也是作為標準支持的。 不然報異常信息: javax.servlet.ServletException:Circular view
- path [/helloJsp]: would dispatch back to the current handler URL[/helloJsp]
- again. Check your ViewResolver setup! (Hint: This may be the resultof an
- unspecified view, due to default view name generation.) --
>
<dependency>
<groupId>
javax.servlet</groupId>
<artifactId>
jstl</artifactId>
</dependency>
- <!-- tomcat的支持. -->
<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>
net.sf.flexjson</groupId>
<artifactId>
flexjson</artifactId>
<version>
2.1</version>
</dependency>
</dependencies>
2.2配置application.properties
[html] view plain copy
- spring.mvc.view.prefix=/WEB-INF/user/
- spring.mvc.view.suffix=.jsp
- application.hello=HelloAngel From application
2.3、controller按正常的mvc規範寫即可
![](https://pic.pimg.tw/zzuyanan/1488615166-1259157397.png)
![](https://pic.pimg.tw/zzuyanan/1482887990-2595557020.jpg)
TAG:程序員小新人學習 |