极简-如何快速创建SpringBoot的web项目

通过Idea创建SpringBoot有以下三种方式

1、通过官网下载对应包导入到idea中
2、通过idea的脚手架创建
3、创建后自己添加依赖

对于初学者我们采用第三种方式创建比较简单明了

1、通过idea创建project

2、填写名称,点击create在这里插入图片描述
3、在pom.xml中添加依赖

<!--添加spring-boot-starter依赖-->
<dependencies>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.7.0</version>
</dependency>
</dependencies>

4、创建类,名字自己起一个就行

package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author 
 * @version 10.15
 * @description: TODO
 * @date 2024/4/26 10:50
 */
@SpringBootApplication
public class SpringBootAopApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAopApplication.class,args);
    }
}

5、启动项目即可,springboot的web项目创建完成
在这里插入图片描述
6、创建一个controller访问试试

package org.example;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/aop")
@RestController
public class HelloSpringBoot {
    @GetMapping("/add")
    public Integer add(Integer a,Integer b){
        System.out.println(a+"-"+b);
        return a+b;
    }
}

7、通过前台页面访问
http://localhost:8080/aop/add?a=1&b=2
在这里插入图片描述

  • 11
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值