Spring Boot + MyBatis 电商项目 - 02- 引入 Spring Boot 依赖包

版权声明:本文为博主原创文章,欢迎转载,转载请注明出处 https://blog.csdn.net/qq_40147863/article/details/85878056

Spring Boot + MyBatis 电商项目 - 02- 引入 Spring Boot 依赖包

上一篇 Spring Boot + MyBatis 电商项目 - 01- 开题 + 创建项目 我们已经创建好了 quickstart 项目

一、加载 Spring Boot 依赖包,配置 pom.xml 文件:

方法一:

百度:maven Spring Boot ,点第一个:

点进去都点第一个最新版就可以:
(1)Spring Boot Test Starter:

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>2.1.1.RELEASE</version>
    <scope>test</scope>
</dependency>

(2)Spring Boot Web Starter:

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.1.1.RELEASE</version>
</dependency>

(3)拷贝到项目的 pom.xml 文件中,注意位置:

方法二

(1)打开官方文档:

(2)展开 Build with Maven,有配置文件:

二、不管哪个方法,再引入一个:

<dependency>
	<groupId>com.jayway.jsonpath</groupId>
	<artifactId>json-path</artifactId>
	<scope>test</scope>
</dependency>

三、指定 parent ,注意位置:

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

位置:

四、简单编写 App.java 文件:

package com.miaoshapro;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Hello world!
 *
 */

//自动配置注解,自动扫描,加载到项目工程中
@EnableAutoConfiguration
//
@RestController
public class App {

    //请求映射,当请求 /home 时执行该方法
    @RequestMapping("/home")
    public String home(){
        return "Hello home!";
    }

    public static void main( String[] args ) {

        System.out.println( "Hello World!" );

        //启动 Web 容器
        SpringApplication.run(App.class, args);
    }
}

五、运行服务器

控制台会打印:

六、打开浏览器访问:

http://localhost:8080/home

home 是刚才设置的映射路径

更多文章链接

猜你喜欢

转载自blog.csdn.net/qq_40147863/article/details/85878056
今日推荐