eclipse中搭建springboot学习(2)---第一个helloword项目

打开eclipse,new-Spring Starter Project-next

eclipse中搭建springboot学习(2)---第一个helloword项目

设置项目名称-next

eclipse中搭建springboot学习(2)---第一个helloword项目

选择web-next

eclipse中搭建springboot学习(2)---第一个helloword项目

点击finish即可

eclipse中搭建springboot学习(2)---第一个helloword项目
写一个controller

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
    
    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "spring boot!!!!";
    }
}

 注意:自己写的controller与DemoApplication.java放在同一个包下

eclipse中搭建springboot学习(2)---第一个helloword项目

运行项目

eclipse中搭建springboot学习(2)---第一个helloword项目

运行完成后,访问http://localhost:8080/hello既可以看到运行结果