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

前端页面的显示结果

相关推荐
期待のcode1 小时前
Spring框架1—Spring的IOC核心技术1
java·后端·spring·架构
鼠鼠我捏,要死了捏1 小时前
Spring Boot Actuator自定义指标与监控实践指南
spring boot·监控·actuator
葵野寺1 小时前
【RelayMQ】基于 Java 实现轻量级消息队列(七)
java·开发语言·网络·rabbitmq·java-rabbitmq
书院门前细致的苹果1 小时前
JVM 全面详解:深入理解 Java 的核心运行机制
java·jvm
上官浩仁2 小时前
springboot excel 表格入门与实战
java·spring boot·excel
Livingbody2 小时前
10分钟完成 ERNIE-4.5-21B-A3B-Thinking深度思考模型部署
后端
Hello.Reader2 小时前
从零到一上手 Protocol Buffers用 C# 打造可演进的通讯录
java·linux·c#
树码小子3 小时前
Java网络初识(4):网络数据通信的基本流程 -- 封装
java·网络
稻草人想看远方3 小时前
GC垃圾回收
java·开发语言·jvm
胡萝卜的兔3 小时前
go 日志的分装和使用 Zap + lumberjack
开发语言·后端·golang