java后端springboot单/多模块搭建教程

本文详细介绍了如何使用Java和Spring Boot进行单模块和多模块项目的搭建,包括环境准备、工程创建、POM配置、主启动类编写、Controller创建、项目部署等步骤,涵盖jar包和war包的运行方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

单模块springboot

一、搭建准备

1. java开发环境(jdk)
2. maven安装
3. idea代码编写工具

二、创建工程

1. 新建maven工程

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2. 修改pom文件

修改前:

<?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>

    <groupId>com.hx</groupId>
    <artifactId>helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>
    
</project>

修改后:

<?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>

    <groupId>com.hx</groupId>
    <artifactId>helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!--    springboot2.3.4.RELEASE版本-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>

    <dependencies>
        <!--        web开发启动器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>

3. 新建主启动类

在这里插入图片描述

package com.test;

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

/**
 * @ClassName HelloWorldApplication
 * @Description 主程序类
 * @Author WTT
 * @Date 2023/7/3 10:15
 * @Version 1.0
 **/
@SpringBootApplication
public class HelloApplication {
   
   
    public static void main(String[] args) {
   
   
        SpringApplication.run(HelloApplication.class,args);
    }
}

4. 新建controller在这里插入图片描述

package com.test.controller;

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

/**
 * @ClassName HelloController
 * @Description
 * @Author WTT
 * @Date 2023/7/3 10:41
 * @Version 1.0
 **/
@RestController
public class HelloController {
   
   

    @GetMapping("handle")
    public String handle(){
   
   
        return "hello,boys!";
    }

}

5. 启动主启动类,访问接口

在这里插入图片描述

5. 修改访问端口

在这里插入图片描述访问接口:
在这里插入图片描述

三、项目部署

jar包运行
<?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>

    <groupId>com.hx</groupId>
    <artifactId>helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <!--    springboot2.3.4.RELEASE版本-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>

    <dependencies>
        <!--        web开发启动器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值