SpringBoot的创建方式

SpringBoot创建的五种方式

1.通过Springboot官网链接下载

注意SpringBoot项目的封装方式默认为Jar

需要查看一下,自己的Maven版本是否正确

创建成功

2.通过 aliyun官网链接下载

修改服务路径为阿里云链接

创建成功

3.通过Springboot官网下载

点击,拉到最下方

基础配置,如果想要添加依赖

最后,点击GENERATE生成项目包

import 对应的pom.xml

一直点击next,直到finish打开文件

更改配置信息,完成SpringBoot项目创建

4.通过aliyun官网下载

访问官网

注意必须为单模块

5.将mavenJava改成springboot

复制代码
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!--添加父工程目录 为了更好的将子目录交给SpringBoot管理-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.qcby</groupId>
    <artifactId>springboot122105</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--添加内容-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--加载web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

加入启动类

复制代码
package com.qcby.springboot;

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

//扫描所有dao接口
//@MapperScan("com.qcby.springBootDemo1031.dao")
@SpringBootApplication
public class SpringBootDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);
    }
}

我们可以使用自己搭建的SpringBoot进行简单的页面输出

在springboot下面创建controller包,并创建一个表现层的方法

复制代码
package com.qcby.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/index")
public class IndexController {
    @RequestMapping("/run")
    public void run(HttpServletResponse response) throws IOException {
        System.out.println("121212");
        response.getWriter().write("hello");
    }
}

直接运行启动类的内容

使用嵌入式的 Servlet 容器 Tomcat,应用无需打成 war 包,内嵌Tomcat

前端页面的显示结果

相关推荐
掘金者阿豪17 小时前
🚀 CentOS Stream 9服务器Docker部署KWDB:从零到跨模查询实战全记录
后端
yang_xin_yu17 小时前
一文带你精通泛型PECS原则与四大核心函数式接口
后端
孟陬17 小时前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端
树獭叔叔17 小时前
13-KV Cache与位置编码表:大模型推理加速的核心技术
后端·aigc·openai
想用offer打牌17 小时前
一站式了解四种限流算法
java·后端·go
嘻哈baby17 小时前
用 C++ 写线程池是怎样一种体验?
后端
嘻哈baby17 小时前
SQL Server 和 Oracle 以及 MySQL 有哪些区别?
后端
绝无仅有17 小时前
Redis过期删除与内存淘汰策略详解
后端·面试·架构
武子康17 小时前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
绝无仅有17 小时前
Redis大Key问题排查与解决方案全解析
后端·面试·架构