一、题目需求
使用SpringBoot开发一个web应用,浏览器发起/hello后,浏览器返回字符串"Hello Word"
二、操作步骤
然后创建一个类,并且加上 @RestController让该类变成请求处理类,在定义一个方法,加上
@RequestMapping("/hello")表示请求路径。
package com.test.huang.huang1;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 请求处理类
@RestController
public class Test {
// 请求路径
@RequestMapping("/hello")
public String hello(){
return "Hello Word";
}
}
然后在启动类中启动程序
最后在浏览器中输入http://localhost:8080/hello显示此页面表示SpringBoot 项目成功运行。