通过maven创建项目
先看下目录结构
1、pom.xml 导入springboot的依赖
<!-- 指定Spring Boot的版本1.5.9.RELEASE --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <!-- 导入Spirng Boot web 所需的jar包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>2、创建一个主程序
package cn.orz; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HelloWorldMainApplication { public static void main(String[] args) { SpringApplication.run(HelloWorldMainApplication.class,args); } }3、创建一个controller层处理业务
package cn.orz.cn.orz.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class helloworldcontraller { @ResponseBody @RequestMapping("/hello") public String hello(){ return "Hello World"; } }4.测试 效果如下 5.打包成jar包 6.启动程序
C:\Users\orz>cd C:\Users\orz\Desktop C:\Users\orz\Desktop>java -jar Spring-Boot-01-HelloWorld-1.0-SNAPSHOT.jar二、快速创建SpringBoot项目