• SpringBoot的搭建(两种方式)


    SpringBoot的搭建

    一、简介
    特点:springboot简化配置,使项目更简单管理和操作,提高开发效率

    二、配置环境要求
    依赖springboot2.0以上
    jdk8及以上
    idea

    三、搭建方法两种:
    使用maven方式和idea自带的spring initializr创建

    其一
    使用maven创建:

    1 使用intelligent IDEA 创建一个名为SpringBootUnion的maven项目

    2 在该项目的pom.xml中导入相关依赖
    完整pom.xml内容

    
    
        4.0.0
    
        org.example
        springboot2022
        1.0-SNAPSHOT
    
        
            8
            8
        
    
        
            
            
                org.springframework.boot
                spring-boot-starter-web
                2.6.3
            
            
                org.springframework.boot
                spring-boot-starter-test
                2.6.3
                test
            
        
    
    
    
    • 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

    3 项目包框架
    在项目的src包下的main包中的java包下创建自己的项目结构包,如下
    在这里插入图片描述

    4 在自己创建的包下创建一个主程序SpringBootUnionApplication.java,用于启动springboot

    package com.jwh.springboot.springboot;
    
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    
    /**
    * @author JING
    */
    @SpringBootApplication
    public class SpringBootUnionApplication {
        public static void main(String[] args) {
            SpringApplication.run(SpringBootUnionApplication.class,args);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    5 在controller包里新建一个controller SpringBootUnionController.java,测试springboot启动成功

    package com.jwh.springboot.springboot.controller;
    
    import org.springframework.http.MediaType;
    import org.springframework.web.bind.annotation.CrossOrigin;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
    * @author JING
    * 此处只能用@RestController注解,不能用@Controller,不然会报错
    */
    @RestController
    @RequestMapping("/springboot")
    public class SpringBootUnionController {
            @CrossOrigin
            @RequestMapping(value = "/test",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        public String test(){
                return "springboot install successfully!";
            }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    6 启动SpringBootUnionApplication.java主程序,
    启动成功的界面
    在这里插入图片描述

    7 使用postman 访问路径为 127.0.0.1:8080/springboot/test
    在这里插入图片描述

    8 结果返回,项目可以正常使用
    在这里插入图片描述

    其二
    使用spring initializr

    1 新建项目 如图选择Spring Initializr 创建
    在这里插入图片描述

    2 选择web - spring web
    在这里插入图片描述

    3 选择finish 界面如图
    在这里插入图片描述

    4 项目包结构
    在这里插入图片描述

    5 启动项也自动创建好了,编写controller类进行测试,同之前maven创建后的测试一样

    结束!

  • 相关阅读:
    【算法练习】数组操作
    XrayGLM - 医学大模型
    HarmonyOS—UI开发性能提升的推荐方法
    嵌入式开发--RS-485通讯的问题
    Android学习笔记 9. PopupWindow
    阿里云服务器ECS windows server已开放端口但连不上的问题
    华为云云耀云服务器L实例评测|华为云上安装监控服务Prometheus三件套安装
    计算机组成原理_Cache写策略
    C++智能指针种类以及使用场景
    Linux 内存泄漏检测的基本原理
  • 原文地址:https://blog.csdn.net/m0_67393157/article/details/126515335