1.创建一个maven项目
2打开pom.xml
<dependencies>
<!-- 引入Springboot Web依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- 引入继承springboot-parent 实现了很多jar包依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
然后右击项目-maven-update source eclipse会自动下载jar包
然后创建一个controller包
新建类
package com.news.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class TestController {
@RequestMapping("/hello")
public String hello(){
return "success";
}
public static void main(String[] args){
//开始运行
SpringApplication.run(TestController.class, args);
}
}
然后运行,默认端口8080加上@RequestMapping里面写的映射路径
spring boot 注解:
@RestController == @Controller + @ResponseBody
@ResponseBody这个是会返回json