以下:java
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>Springboot</artifactId> <packaging>war</packaging> <name>Springboot Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
一、首先建立一个Application类,里面添加一个main()方法,web
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
须要注意的是:这个类的上面须要添加SpringBoot的注解@SpringBootApplication,而后在主函数中开始启动。spring
二、而后建立一个HelloWord类,用来测试SpringBootapache
以下:浏览器
@RestController @EnableAutoConfiguration public class HelloWord { @RequestMapping("/hello") public String hello() { return "hello,Spring boot!"; } //带参数 @RequestMapping("/word/{name}") public String word(@PathVariable String name) { return "word--spring boot:" + name; } }
须要注意的是这上面的几个注解:springboot
Ok,就这样,一个简单的SpringBoot小demo就写出来了,咱们直接就能够运行了,而后输入:http://localhost:8080/hello 和 http://localhost:8080/word/canshu 浏览器上便可获得输出结果服务器