• [学习笔记] SpringBoot 之 Helloworld


    创建项目

    IDEA / File / New / Project / Spring Initalizr / Next

    Group: com.wu            公司官网域名反写
    Artifact: helloworld     项目的名字,项目根目录的名称
    Version: 0.0.1-SNAPSHOT  当前的版本,SNAPSHOT为开发版,Release为稳定版
    Name: helloworld         启动类的类名
    Package: com.wu.helloworld    包名
    Dependencies: Web / Spring Web  引入 tomcat,dispatcherServlet,xml 等依赖
                  Developer Tools / Spring Boot DevTools  热部署工具,可选
    

    项目主要文件

    程序主入口:

    src/main/java/com/wu/helloworld/HelloworldApplication

    核心配置文件:

    src/main/resources/application.properties

    单元测试:

    src/test/java/com/wu/helloworld/HelloworldApplicationTests

    依赖配置文件:

    pom.xml

    pom.xml 说明

    <!-- 父依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/>
    </parent>
    
    <dependencies>
        <!-- web场景启动器 -->
        <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>
            <!-- 新版本 spring-boot-starter-test 默认使用 Junit5,需要剔除 vintage 依赖 -->
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <!-- 打包插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- 单元测试插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!-- 跳过单元测试,跳过编译单元测试代码 -->
                    <skip>true</skip>
                    <!-- 跳过单元测试,但会编译单元测试代码 -->
                    <!-- <skipTests>true</skipTests> -->
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    编写代码

    创建目录:

    src/main/java/com/wu/helloworld/controller

    src/main/java/com/wu/helloworld/dao

    src/main/java/com/wu/helloworld/pojo

    src/main/java/com/wu/helloworld/service

    # src/main/java/com/wu/helloworld/controller/HelloController
    
    @RestController
    @RequestMapping("/hello")
    public class HelloController {
    	@GetMapping("/world")
    	public String world() {
    		return "Hello, world!";
    	}
    }
    

    测试运行

    执行打包:

    Maven Projects / helloworld / Lifecycle / package

    打包目录:

    target/helloworld-0.0.1-SNAPSHOT.jar

    运行程序:

    target> java -jar .helloworld-0.0.1-SNAPSHOT.jar
    

    访问测试:

    http://localhost:8080/hello/world

  • 相关阅读:
    java面向对象基础
    java重载方法、重写方法
    java数据类型
    Java简介
    随机读写,块读写
    Java基本常识

    循环双向链表
    双向链表(链表)
    循环单链表(链表)
  • 原文地址:https://www.cnblogs.com/danhuang/p/12532612.html
Copyright © 2020-2023  润新知