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

前端页面的显示结果

相关推荐
曹牧4 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
KYGALYX4 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了4 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
爬山算法5 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7255 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎5 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄5 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
Moment5 小时前
富文本编辑器在 AI 时代为什么这么受欢迎
前端·javascript·后端
忆~遂愿5 小时前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略
java·大数据·linux·人工智能
小韩学长yyds6 小时前
Java序列化避坑指南:明确这4种场景,再也不盲目实现Serializable
java·序列化