spring学习笔记(四)springboot 入门

1.8 使用向导快速创建SpringBoot项目

IDE都支持使用Spring的项目创建向导快速创建按建springBoot应用(联网)

1.步骤:

1.1 打开New Project 里有个Spring Initializr

1.2 选择jdk的版本(1.8)后,点击下一步,并填写项目信息,如下

1.3 选择模块启动器--只选spring web starter模块启动器

 1.4 点击next,再次点击finish完成快速创建,联网从springboot官网生成需要的启动项

1.5 查看生成的pom文件

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.atguigu</groupId>
    <artifactId>springboot-01-helloworld-quick</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-01-helloworld-quick</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <!-- springboot 单元测试功能 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

1.6 主程序

package com.atguigu.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Springboot01HelloworldQuickApplication {

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

}

1.7 controller

package com.atguigu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//这个类的所有方法返回的数据直接写给浏览器,如果是对象转为json数据
//@ResponseBody
//@Controller
//restController是@ResponseBody和@Controller的合体
@RestController
public class HelloController {


    @RequestMapping("/hello")
    public String hello() {
        return "Hello World";
    }

    //RESTAPI方式

}

1.8 启动并访问hello请求

2.简单介绍默认生成的springboot项目:

2.1 主程序已经生成了,我们只需要编写我们自己的逻辑

2.2 resources文件夹中的目录结构

      statics:保存所有的静态资源;js,css,images等

      templates:保存所有的模板页面:SpringBoot默认jar包使用嵌入式的tomcat,默认不支持jsp页面,可以使用模板引擎                                    (freemarker,thymeleaf);

      application.properties:默认的springBoot的配置文件,所有默认的配置文件都可以在这个配置文件中修改(如tomcat端口                                                  号  server.port = 8081)

2.SpringBoot配置

2.1 配置文件application

1.SpringBoot使用一个全局的配置文件,配置文件名固定(resources下的二选一)

       application.properties文件

       application.yml文件

2.配置文件的作用:修改springBoot自动配置的默认值,springBoot在底层都给我们配置好了

3.YAML(YAML Ain't Markup Language):是一个标记语言??

4.标记语言:

    以前的配置文件:大多都是使用xxx.xml的形式

    YAML:以数据为中心,比json,xml更适合做配置文件

    示例:--yaml

server:
  port: 8081

   xml:

<server>
    <port>8081</port>
</server>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值