目录 

1.idea创建入门springboot

 

创建主启动类,

     IDEA使用个人记录1图一

项目目录的2中方式

一,主程序和被扫描包在同一路径下(共有一个直接父级包),此时默认自动扫描主程序父级包下所有类。不需要

@ComponentScan注解。

IDEA使用个人记录1图二

二.主程序和被扫描包不在统一直接父级目录包下,需要添加@ComponentScan扫描注解,路径写到包路径即可。

IDEA使用个人记录1图三

 

IDEA使用个人记录1

@Controller          标志这是一个controller

@RequestMapping    访问请求

@ResponseBody     表示该方法的返回结果直接写入 HTTP response body 中。


 

2.IDEA使用spring Initializr 创建springboot项目

一:File -----New Project 

IDEA使用个人记录1图1

二:填信息----Next

IDEA使用个人记录1图2

IDEA使用个人记录1图3

{Finish------主程序已经生成好,我们只需要自己写controller等逻辑代码,  


下面看一下它的pom.xml文件

IDEA使用个人记录1图4

spring-boot-starter-parent 作为父依赖,我们点进去看看,发现他的上一级是spring-boot-dependencies,

IDEA使用个人记录1图5

再进去看看如下:

IDEA使用个人记录1图6

这其实是他的版本仲裁中心,下面的版本号列举了几乎很多的依赖版本,以至于我们导入依赖,不需要写版本号。


pom还有一个重要部分是

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

这个作为场景启动器,也就是我们刚刚图3说的选择场景启动器,它会自动帮我们导入需要的start.


          

相关文章: