2.创建一个简单的SpringBoot

开发工具:Eclipse,Maven

  2.1.首先创建一个工作空间

     2.1.1.开始创建空间

  点击“new”=》other ,然后输入框输入“work”,选择“Java Working Set”; 输入工作空间的名字“SpringBoot自学练习集合”,点击“完成”

    然后 :

        选择 Select Work Set =》如图显示

 

 

 显示出来工作空间。

 2.2.创建一个SpringBoot项目

 2.2.1.创建项目步骤

 .点击“new”=》other=》Maven=》Maven Project=》next=》next 然后选择

 

 

 

 点击Next

 

 

 这里输入“com.hundsun.test”, 项目名称:SpringBootTest

2.2.2.在pom.xml文件中添加如下配置

添加到url下面

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.9.RELEASE</version>
</parent>

 原理作用:    构建基于Spring Boot 的应用首先必须要将<parent..../>元素设置为 Spring boot的 spring-boot-starter-parent,spring-boot-starter-parent是Spring Boot的核心启动器,

包含了自动配置,日志和YAML等大量默认的配置,大大简化了我们的开发。<version..../> 元素建议使用最新的RELEASE版本,之后的SpringBoot模块(如spring-boot-starter-web模块)

都会自动选择最合适的版本进行添加。

 

  在<dependencies..../>内添加一个<dependency..../>

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

 

 <dependency...../> 元素用于添加需要的starter模块。

Spring Boot中包含许多的Starter模块,简单的说每一个starter都是一系列的依赖包的组合。

   starter-web模块,就是包含了Spring Boot预定义的一些Web开发的常用依赖包,支持全栈式Web开发,包括Tomcat和spring-web,Springmvc,由于指定得spring-boot-starter-parent,

  所以此处的web starter模块不需要指定版本,Spring Boot 会自动选择最合适的版本进行添加。

2.2.3.开始写控制器

  在包里面创建包controller,在包里里面创建类,类名是HelloController,如下图:

 

 

 

修改app.java

 

 

 2.2.4.启动app中的main方法就可以在浏览器中输入http://localhost:8080/hello

 

 

 

 

 

 

 

 

 

 

 

posted @ 2019-11-21 18:40  繁华纤尽依然保持初心  阅读(189)  评论(0)    收藏  举报