Springboot入门(一)

利用idea创建项目

Springboot入门(一)_第1张图片
Springboot入门(一)_第2张图片

  • spring-boot-starter-web:核心模块,包括自动配置支持,日志和yaml
  • spring-boot-starter-test:测试模块,包括JUnit、Hamcrest、Mockito。

编写Controller


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello world!";
    }
}

@RestController的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置

启动程序,访问接口

打开浏览器访问http://localhost:8080/hello

你可能感兴趣的:(Springboot)