使用Spring Initializer快速创建项目
首先肯定是打开我们的IDEA的编辑器呀~
File -> New -> Project
Spring Initializr -> JDK版本 -> Next
Group -> Artifact -> Description
需要什么模块选择什么模块,我这里只选择Web功能
最后一步咯
等待模块导入完成
右击->New->Java Class
写入Controller注解
package com.wangyang.springboot01helloworldquick.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
//@ResponseBody //这个类的所有方法返回的数据直接写给浏览器(如果是对象转为json数据)
//@Controller
/**
* @RestController == @ResponseBody + @Controller
*/
@RestController
public class HelloWorld {
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
}
访问