美文网首页
SpringDemo实践

SpringDemo实践

作者: 编程放大镜 | 来源:发表于2023-08-07 11:03 被阅读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

    相关文章

      网友评论

          本文标题:SpringDemo实践

          本文链接:https://www.haomeiwen.com/subject/fjkgpdtx.html