Human0722's blog Human0722's blog
首页
  • Spring

    • Spring Framework
    • Spring Boot
    • Spring Cloud
  • CCNA
  • Vue

    • Vue2
日本语
导航
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Human0722

Gravity always win
首页
  • Spring

    • Spring Framework
    • Spring Boot
    • Spring Cloud
  • CCNA
  • Vue

    • Vue2
日本语
导航
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Spring Framework

  • Spring Boot

    • HelloWorld
      • 异常处理
      • 参数校验
      • 配置文件
      • Filter & Interceptor
      • Spring MVC 启动流程分析
      • DefineSprintBootStarter
    • Java 类库

    • 数据库

    • 解决方案

    • Java.Content
    • Spring Boot
    Xueliang
    2022-05-19
    目录

    HelloWorld

    SpringBoot 2.x

    # 文件夹结构是这样的

    # 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.5.14-SNAPSHOT</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>SpringBootCase</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>SpringBootCase</name>
        <description>SpringBootCase</description>
        <properties>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <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>
    </project>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

    # 主函数这样写

    @SpringBootApplication
    public class SpringBootCaseApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(SpringBootCaseApplication.class, args);
        }
    
    }
    
    1
    2
    3
    4
    5
    6
    7
    8

    # 配置文件这样写

    server:
      port: 8080
    
    1
    2

    # 再来个 Controller

    package com.example.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * @author xueliang
     * @description TODO
     * @date 2022-05-19 16:54
     */
    @RestController
    public class HelloWrold {
    
        @RequestMapping("/hello,world")
        public String hello() {
            return "hello,world";
        }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    # 跑起来

    # 完事

    Spring Transaction 事务
    异常处理

    ← Spring Transaction 事务 异常处理→

    最近更新
    01
    DefineSprintBootStarter
    03-23
    02
    Spring MVC 启动流程分析
    03-23
    03
    Redis
    03-23
    更多文章>
    Theme by Vdoing | Copyright © 2019-2024 Human0722 | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式