首先须要引入jar包html
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <type>pom</type> </dependency> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-web</artifactId>--> <!--<version>1.5.4.RELEASE</version>--> <!--</dependency>--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.0.2.RELEASE</version> </dependency>
第二个jar包注释掉了,由于第三个jar包里面已经依赖了它。第三个jar包是视图解析器web
接下来,就能够写启动类了spring
package com; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Created by zhangsan 2017/8/24 0024. */ //启动类的注解 @SpringBootApplication public class ApplicationStart { //main方法启动 public static void main(String[] args) { SpringApplication.run(ApplicationStart.class); } }
注意:启动类的包必定在其余contrller、service、dao等的上级。由于springboot只扫描启动类子包下面的类。springboot
而后咱们写一个页面,目录结构以下app
为何要放在templates包下呢,由于thymeleaf视图解析器默认是在这个目录下找html文件的。固然这个是能够配置的,配置就是在application.properties里了spring-boot
而后,咱们写一个controller试试吧htm
package com.mmm.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Created by zhangsan on 2017/8/24 0024. * 此处注解用Controller,而不是RestController * RestController = Controller + ResponseBody * 因此,若是使用RestController,则至关于给每一个方法都 * 加了ResponseBody注解,而这个注解的意思是,方法的返回值是什么 * 就返回什么内容。因此视图解析器就不会产生做用了 */ @Controller public class ViewController { @RequestMapping("/index") public String redirect(){ return "index"; } }
访问结果io
OK,成功。class