本人博客都是手写,如有错误,请指正。。。。
最近Spring Boot很火啊,看完基础教程,闲着没事,干脆自己动手搭建一个基本sb环境玩玩。
先用截图创建一个Spring Boot项目吧
到这儿,我们的SB项目就创建完成了,现在走一个hello world玩玩。
在我们的demo包下建一个web包,新建一个类,HelloController
HelloController代码如下:
package com.example.demo.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by zhoufei on 2017/8/28.
*/
@RestController //@RestController注解相当于@Controller注解+@ResponseBody注解,就是返回JSON喽
@RequestMapping("/")
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello world";
}
}
启动一下DemoApplication
访问 http://localhost:8080/hello
得到如下页面
大功告成!!!!!!!