當前位置:
首頁 > 知識 > springmvc+jsp轉spring boot結構 前後端分離

springmvc+jsp轉spring boot結構 前後端分離

1、前端

1.1、頁面遷移到resourecs,這個位置可以自己定義

springmvc+jsp轉spring boot結構 前後端分離

1.2、加入插件

[html] view plain copy

  1. <build>

  2. <plugins>

  3. <!-- spring dev -->
  4. <plugin>

  5. <groupId>

    org.springframework.boot

    </groupId>

  6. <artifactId>

    spring-boot-maven-plugin

    </artifactId>

  7. <version>

    1.4.2.RELEASE

    </version>

  8. <configuration>

  9. <mainClass>

    test.Application

    </mainClass>

  10. </configuration>

  11. <executions>

  12. <execution>

  13. <goals>

  14. <goal>

    repackage

    </goal>

  15. </goals>

  16. </execution>

  17. </executions>

  18. <dependencies>

  19. <!-- spring熱部署 -->
  20. <dependency>

  21. <groupId>

    org.springframework

    </groupId>

  22. <artifactId>

    springloaded

    </artifactId>

  23. <version>

    1.2.6.RELEASE

    </version>

  24. </dependency>

  25. </dependencies>

  26. </plugin>

  27. <!-- 忽略無web.xml警告 -->
  28. <plugin>

  29. <groupId>

    org.apache.maven.plugins

    </groupId>

  30. <artifactId>

    maven-war-plugin

    </artifactId>

  31. <configuration>

  32. <failOnMissingWebXml>

    false

    </failOnMissingWebXml>

  33. </configuration>

  34. </plugin>

  35. </plugins>

  36. <resources>

  37. <!-- 打包時將jsp文件拷貝到META-INF目錄下 -->
  38. <resource>

  39. <!-- 指定resources插件處理哪個目錄下的資源文件 -->
  40. <directory>

    src/main/resources/META-INF/resources/WEB-INF

    </directory>

  41. <!--注意此次必須要放在此目錄下才能被訪問到 -->
  42. <targetPath>

    META-INF/resources

    </targetPath>

  43. <includes>

  44. <include>

    **/**

    </include>

  45. </includes>

  46. </resource>

  47. <resource>

  48. <directory>

    src/main/resources

    </directory>

  49. <includes>

  50. <include>

    **/**

    </include>

  51. </includes>

  52. <filtering>

    false

    </filtering>

  53. </resource>

  54. </resources>

  55. </build>

注意:需要制定文檔位置和打包的文件位置


2、後端

2.1、依賴,包括前端、jsp、springboot的依賴

[html] view plain copy

  1. <dependencies>

  2. <dependency>

  3. <groupId>

    com.example

    </groupId>

  4. <artifactId>

    demo-spring-ui

    </artifactId>

  5. <version>

    0.0.1-SNAPSHOT

    </version>

  6. </dependency>

  7. <!--

    <dependency>

    <groupId>

    org.springframework.boot

    </groupId>

    <artifactId>

    spring-boot-starter-thymeleaf

    </artifactId>

  8. </dependency>

    --

    >

  9. <dependency>

  10. <groupId>

    org.springframework.boot

    </groupId>

  11. <artifactId>

    spring-boot-starter-web

    </artifactId>

  12. </dependency>

  13. <!-- servlet依賴. -->
  14. <dependency>

  15. <groupId>

    javax.servlet

    </groupId>

  16. <artifactId>

    javax.servlet-api

    </artifactId>

  17. <scope>

    provided

    </scope>

  18. </dependency>

  19. <!-- JSTL(JSP Standard TagLibrary,JSP標準標籤庫)是一個不斷完善的開放源代碼的JSP標籤庫,是由apache的jakarta小組來維護的。JSTL只能運行在支持JSP1.2和Servlet2.3規範的容器上,如tomcat
  20. 4.x。在JSP2.0中也是作為標準支持的。 不然報異常信息: javax.servlet.ServletException:Circular view
  21. path [/helloJsp]: would dispatch back to the current handler URL[/helloJsp]
  22. again. Check your ViewResolver setup! (Hint: This may be the resultof an
  23. unspecified view, due to default view name generation.) --

    >

  24. <dependency>

  25. <groupId>

    javax.servlet

    </groupId>

  26. <artifactId>

    jstl

    </artifactId>

  27. </dependency>

  28. <!-- tomcat的支持. -->
  29. <dependency>

  30. <groupId>

    org.springframework.boot

    </groupId>

  31. <artifactId>

    spring-boot-starter-tomcat

    </artifactId>

  32. <scope>

    provided

    </scope>

  33. </dependency>

  34. <dependency>

  35. <groupId>

    org.apache.tomcat.embed

    </groupId>

  36. <artifactId>

    tomcat-embed-jasper

    </artifactId>

  37. <!--<scope>provided</scope> -->
  38. </dependency>

  39. <dependency>

  40. <groupId>

    net.sf.flexjson

    </groupId>

  41. <artifactId>

    flexjson

    </artifactId>

  42. <version>

    2.1

    </version>

  43. </dependency>

  44. </dependencies>

2.2配置application.properties

[html] view plain copy

  1. spring.mvc.view.prefix=/WEB-INF/user/
  2. spring.mvc.view.suffix=.jsp
  3. application.hello=HelloAngel From application

2.3、controller按正常的mvc規範寫即可

springmvc+jsp轉spring boot結構 前後端分離


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

文字跳動特效表白網頁
對比幾個三維重建系統

TAG:程序員小新人學習 |