使用eclipse创建springboot项目

1、安装sts工具

Help -> Eclipse Marketplace…

Search或选择“Popular”标签,选择Spring Tool Suite (STS) for Eclipse插件,安装

2、new project ,选择spring -> spring starter project

使用eclipse创建springboot项目_第1张图片

3、按自己的信息填写,我这里项目名叫demo-2

使用eclipse创建springboot项目_第2张图片

4、选择版本和组件

使用eclipse创建springboot项目_第3张图片
我这里选了1.5.10版本,选了mysql和web,因为是web项目,都会选择web这个选项,其他的可以按自己需要选择,点击 Finish ,就会有一个新项目,不过需要等待几分钟,sts工具会生成spring boot目录的结构及文件

5、可以看到,项目结构已经生成完毕

使用eclipse创建springboot项目_第4张图片

6、查看pom.xml文件

使用eclipse创建springboot项目_第5张图片
发现里面有两个依赖,就是刚刚我们选择的web和mysql, 这里就加入了对应的依赖包,所以上面的选择,只是在这里加入依赖而已。

7、写一个自己的Controller测试

@RestController
public class TestController {

    @RequestMapping("/hello1")
    public String test(){
        return "hello,this is a springboot demo";  
    }
}

这里用了@RestController进行测试,也可以写@Controller,写自己的页面

8、运行spring-boot的入口文件Demo2Application.java

@SpringBootApplication
public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }
}

使用eclipse创建springboot项目_第6张图片
启动成功

9、直接在浏览器访问

使用eclipse创建springboot项目_第7张图片

10、注意目录结构

使用eclipse创建springboot项目_第8张图片

application文件,必须在所有包的上面,也就是说,其他的包,需要是application文件所在包的子包

你可能感兴趣的:(springboot)