搭建springboot项目

现在,更新我的第一篇博客,主要是为了记录下自己学习的过程,方便今后回顾

今天的主题是搭建一个springboot项目,我们使用的工具是idea

新建springboot项目

如图,新建一个springboot项目

 

 

主程序代码

package com.example.demo;

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);
    }

}

controller示例代码

package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public String index(){
        return "Hello World!";
    }
}

启动成功

这样,项目启动成功

在浏览器输入http://localhost:8080/hello就可以访问了

成功!

天道酬勤,与君共勉

原文地址:https://www.cnblogs.com/lwhblog/p/10574279.html