SpringDemo实践
2023-08-07 本文已影响0人
编程放大镜
使用 spring initializer 创建向导
可更方便的创建并初始化项目
使用 eclipse 新建 Maven 项目
在菜单栏>File>New>Maven Project
使用 eclipse 新建 SpringBoot 项目
在菜单栏>File>New>Project>Spring Starter Project
在提示步骤中勾选所需,如:spring web
在源码中 scr/main/java 包 com.example.demo 新建一个测试类
右击 包> new > class
写入代码:
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringbootTest {
@GetMapping("/h")
public String Hello() {
return "Hello";
}
}
运行项目
在浏览器访问:http://localhost:8080/h
成功返回 Hello