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

开发IDE:spring tool suite

 

步骤:

1)new --->Spring Starter Project

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

 

 

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

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

 

 

3)下一步后出现下图:

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

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

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

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

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)完成后项目结构如下图


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

 

 

 

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

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

 

 

下面是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.  
  6. <groupId>com.mifeng.test</groupId>

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

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

  9. <packaging>jar</packaging>

  10.  
  11. <name>web-practice</name>

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

  13.  
  14. <parent>

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

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

  17. <version>1.5.1.RELEASE</version>

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

  19. </parent>

  20.  
  21. <properties>

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

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

  24. <java.version>1.8</java.version>

  25. </properties>

  26.  
  27. <dependencies>

  28. <dependency>

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

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

  31. </dependency>

  32. <dependency>

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

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

  35. </dependency>

  36.  
  37. <dependency>

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

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

  40. <scope>test</scope>

  41. </dependency>

  42. </dependencies>

  43.  
  44. <build>

  45. <plugins>

  46. <plugin>

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

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

  49. </plugin>

  50. </plugins>

  51. </build>

  52.  
  53.  
  54. </project>

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