需求:使用SpringBoot开发一个Web应用,浏览器发起请求/hello后,给浏览器返回字符串”Hello world”
1、创建Maven工程
2、导入spring-boot-starter-web依赖
3、编写Controller
package com.walker.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";
}
}
4、启动类
package com.walker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
5、访问http:localhost:8080/hello