spring boot之hello world!

1.使用idea搭建spring boot项目工程,选择Spring Initializr,选中jdk然后next
在这里插入图片描述
2.输入Group,Artifact,选中Maven Project,然后next
在这里插入图片描述
3.选择web->web 然后next,再finish
在这里插入图片描述
4.搭建后项目目录如下
在这里插入图片描述
DemoApplication.java为项目启动入口

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

在DemoApplication.java所在包或所在包的子包下创建HelloController.java

package com.example.demo;

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

@RestController
public class HelloController {
    @RequestMapping("/")
    public String hello(){
        return "hello world!";
    }
}

运行项目,起来后在浏览器输入如下地址即可访问。
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章