1.添加pom依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
</properties>
<dependencies>
<!-- web启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring-boot-starter-parent 作用:
在pom.xml中引入spring-boot-start-parent,它可以提供 dependency management,也就是说依赖管理,引入以后在申明其它dependency 的时候就不需要version了。
spring-boot-starter-web作用:
springweb 核心组件
spring-boot-starter-thymeleaf作用:
用来跳转src/java/main/resources/目录下的html文件
2.新建controller代码
@Controller
@RequestMapping
public class UserService {
@RequestMapping("/hello")
public String helloWord(){
return "helloword";
}
}
3.新建html界面
<body>
hello SpringBoot!
</body>
4.创建启动类
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
运行结果:
附:项目结构