玖叶教程网

前端编程开发入门

springmvc+jsp转spring boot结构 前后端分离

1、前端

1.1、页面迁移到resourecs,这个位置可以自己定义

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规范写即可

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言