spring tool suite新建spring starter project,写一个简单的html页面并运行出来

匿名 (未验证) 提交于 2019-12-02 20:21:24

开发IDE:spring tool suite

步骤:

1)new --->Spring Starter Project

2) 填写项目信息,见下图

3)下一步后出现下图:

因为在上次已经建立过一个基于Spring-boot的web工程,所以Frequently used中出现web、thymeleaf,可以根据实际项目需要选择相应模块,如security等

4)按照提示下一步后再下一步,工程就建立好了,如下图:

5)写一个controller

  
  1. import org.springframework.stereotype.Controller;

  2. import org.springframework.web.bind.annotation.RequestMapping;

  3. import org.springframework.web.bind.annotation.RequestMethod;

  4. @Controller

  5. public class MainController {

  6. @RequestMapping(value="/index",method=RequestMethod.GET)

  7. public String get(){

  8. return "index";

  9. }

  10. }

6)src/main/java中写一个页面(thymeleaf为模板)index.html,页面代码如下:

  
  1. <!DOCTYPE html>

  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">

  3. <head>this is testing</head>

  4. <body>

  5. <td>Hello,mifeng! this is for testing</td>

  6. </body>

  7. </html>

7)完成后项目结构如下图


8)启动项目,浏览器可以看到效果

下面是pom.xml文件:

  
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  4. <modelVersion>4.0.0</modelVersion>

  5. <groupId>com.mifeng.test</groupId>

  6. <artifactId>web-practice</artifactId>

  7. <version>0.0.1-SNAPSHOT</version>

  8. <packaging>jar</packaging>

  9. <name>web-practice</name>

  10. <description>web-practice</description>

  11. <parent>

  12. <groupId>org.springframework.boot</groupId>

  13. <artifactId>spring-boot-starter-parent</artifactId>

  14. <version>1.5.1.RELEASE</version>

  15. <relativePath/> <!-- lookup parent from repository -->

  16. </parent>

  17. <properties>

  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  19. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

  20. <java.version>1.8</java.version>

  21. </properties>

  22. <dependencies>

  23. <dependency>

  24. <groupId>org.springframework.boot</groupId>

  25. <artifactId>spring-boot-starter-thymeleaf</artifactId>

  26. </dependency>

  27. <dependency>

  28. <groupId>org.springframework.boot</groupId>

  29. <artifactId>spring-boot-starter-web</artifactId>

  30. </dependency>

  31. <dependency>

  32. <groupId>org.springframework.boot</groupId>

  33. <artifactId>spring-boot-starter-test</artifactId>

  34. <scope>test</scope>

  35. </dependency>

  36. </dependencies>

  37. <build>

  38. <plugins>

  39. <plugin>

  40. <groupId>org.springframework.boot</groupId>

  41. <artifactId>spring-boot-maven-plugin</artifactId>

  42. </plugin>

  43. </plugins>

  44. </build>

  45. </project>

转自:https://blog.csdn.net/jjf09/article/details/55049506

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!