- 创建Controller
- 添加注解和方法
package com.newcoder.community.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/alpha") //alpha是浏览器访问名
public class AlphaController {
@RequestMapping("/hello")
@ResponseBody
public String sayHello() {
return "Hello Spring Boot";
}
}
- 运行程序并打开http://localhost:8081/community/alpha/hello