• SpringBoot学习日志---初学SpringBoot


    目录

    学习目标

    配置idea

    页面说明

    运行结果

    学习目标

    在idea中配置springboot,并且在浏览器中显示出来,Hello,SpringBoot

    配置idea

     

     

     

     页面说明

     

    YcrkApplication.java
    /**
     * @SpringBootApplication注解说明
     * @SpringBootApplication = (默认属性)@Configuration + @EnableAutoConfiguration + @ComponentScan。
     * 
     * @Configuration+@Bean。使用这两个注解就可以创建一个简单的spring配置类,可以用来替代相应的xml配置文件。
     * @Configuration的注解类标识这个类可以使用Spring IoC容器作为bean定义的来源。@Bean注解告诉Spring,
     * 一个带有@Bean的注解方法将返回一个对象,该对象应该被注册为在Spring应用程序上下文中的bean。
     *
     * @EnableAutoConfiguration:能够自动配置spring的上下文,试图猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置。
     *
     * @ComponentScan:会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller。
     */
    @SpringBootApplication
    public class YcrkApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(YcrkApplication.class, args);
        }
    }

    pom.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <!--    父工程-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <groupId>com.example</groupId>
        <artifactId>ycrk</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>ycrk</name>
        <description>Demo project for Spring Boot</description>
    
        <!--    JDK的版本-->
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-webflux</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

      运行结果

    添加代码文件HelloController

    package com.example.ycrk.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloController {
    
        @GetMapping("hello")
        public String hello(){
            return "Hello,Spring Boot!";
        }
    }

    运行

    链接:http://127.0.0.1:8080/hello

  • 相关阅读:
    一步步搭建自己的web服务器
    http协议知识整理
    数据库系统原理-第一章 数据库系统基本概念
    程序设计入门-C语言基础知识-翁恺-第七周:指针与字符串-详细笔记(七)
    程序设计入门-C语言基础知识-翁恺-第六周:数组-详细笔记(六)
    程序设计入门-C语言基础知识-翁恺-第五周:函数-详细笔记(五)
    程序设计入门-C语言基础知识-翁恺-期中测试
    程序设计入门-C语言基础知识-翁恺-第四周:循环控制-详细笔记(四)
    程序设计入门-C语言基础知识-翁恺-第三周:循环-详细笔记(三)
    程序设计入门-C语言基础知识-翁恺-第二周:简单的计算程序-详细笔记(二)
  • 原文地址:https://www.cnblogs.com/hahayixiao/p/13207862.html
Copyright © 2020-2023  润新知