首页 > 其他分享 >一文通Maven :入门配置详解与最佳实践、进阶技巧、项目案例分析、常用依赖

一文通Maven :入门配置详解与最佳实践、进阶技巧、项目案例分析、常用依赖

时间:2024-09-21 15:51:30浏览次数:3  
标签:依赖 进阶 spring Maven 详解 模块 org com cloud

Maven 是我们开发中的基础工具之一,尤为重要。它不仅仅是构建工具,还是项目管理、依赖管理、插件管理的强大平台。本文将通过对 Maven 配置进行详尽分析,并结合实际项目案例,讨论如何有效配置和优化 Maven,提升项目的管理和开发效率。

一、Maven 基础概念与配置结构

Maven 的核心配置文件是 pom.xml(Project Object Model),通过这个文件,开发者可以管理项目的依赖、构建插件和各种生命周期阶段的行为。下面是典型的 pom.xml 结构:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <properties>
        <java.version>11</java.version>
        <!-- 可配置其他通用属性 -->
    </properties>

    <dependencies>
        <!-- 项目依赖列表 -->
    </dependencies>

    <dependencyManagement>
        <!-- 统一版本管理 -->
    </dependencyManagement>

    <build>
        <!-- 项目构建配置 -->
    </build>
    
    <repositories>
        <!-- 自定义 Maven 仓库 -->
    </repositories>

    <pluginRepositories>
        <!-- 插件仓库 -->
    </pluginRepositories>
</project>

1. groupId, artifactId, version, scope

  • groupId:项目或组织的唯一标识,通常是反向域名格式(例如 com.company)。它帮助 Maven 唯一识别每个项目。

  • artifactId:项目模块的唯一标识,通常是项目名称(例如 user-demo)。它在同一 groupId 下是唯一的。

  • version:项目的版本号,用于区分不同版本的构建成果(例如 0.0.1-SNAPSHOT)。版本控制是维护项目演变的重要工具。

  • scope:依赖的作用范围,决定在什么阶段可用,常见的值包括:

    • compile:默认值,依赖在所有阶段可用,包括编译、测试和运行时。
    • provided:依赖由 JDK 或容器提供,编译时可用,但运行时不可用。
    • runtime:依赖在运行时可用,但编译时不可用。
    • test:依赖只在测试阶段可用,编译和运行时不可用。
    • system:依赖在本地文件系统中,手动指定路径。
    • import:用于导入 BOM(Bill Of Materials)依赖管理。

2. properties

通过 properties 可以定义一些全局属性,例如 Java 版本、编码方式等。常见的属性配置如下:

<properties>
    <java.version>11</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

3. dependencies

Maven 的依赖管理是其最强大的功能之一。通过在 <dependencies> 标签下列出依赖项,Maven 自动处理下载和构建时的依赖关系。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>2.5.4</version>
    </dependency>
</dependencies>

4. dependencyManagement

dependencyManagement 是 Maven 中非常重要的机制,它允许在一个父级 POM 中声明依赖项的版本号,而不需要在每个子项目中手动指定版本号。推荐使用 dependencyManagement 统一管理依赖,特别是在微服务架构中。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.5.RELEASE</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

5. buildplugins

Maven 的构建生命周期非常灵活,可以通过 build 元素定义构建行为,最常见的配置是指定编译器插件及其目标 Java 版本。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

6. repositoriespluginRepositories

默认情况下,Maven 使用中央仓库(Maven Central),但在企业开发中,通常会使用私有仓库(如阿里云 Maven 仓库)。仓库的配置可以通过以下方式添加:

<repositories>
    <repository>
        <id>aliyun-maven</id>
        <url>https://maven.aliyun.com/repository/public</url>
    </repository>
</repositories>

二、Maven 配置文件中的进阶技巧

1. 使用 dependencyManagement 统一管理依赖

在复杂的项目中,依赖项众多,手动管理每个依赖项的版本不仅繁琐,而且容易出现版本冲突。通过 dependencyManagement 可以在父 POM 中统一管理依赖的版本,避免各个子模块独立设置版本,确保项目的一致性。以下是配置步骤与案例说明。

1.1 定义全局属性

首先在 pom.xml 中使用 <properties> 定义各个依赖的版本号。这样,版本管理集中在一处,方便修改和维护。

<properties>
    <java.version>11</java.version>
    <spring-boot.version>2.6.3</spring-boot.version>
    <spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>
    <spring.cloud.version>2021.0.1</spring.cloud.version>
</properties>

1.2 使用 dependencyManagement 统一管理依赖版本

在父 POM 中使用 dependencyManagement 节点,将核心库的版本集中管理。这可以避免在每个子模块中重复指定版本号,同时防止版本冲突。

<dependencyManagement>
    <dependencies>
        <!-- Spring Boot 依赖版本管理 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <!-- Spring Cloud Alibaba 依赖版本管理 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring-cloud-alibaba.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <!-- Spring Cloud 依赖版本管理 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring.cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

1.3 在子模块中使用 dependencyManagement 管理的依赖

子模块只需要引用依赖,而不需要指定版本号,因为版本已经在父 POM 中通过 dependencyManagement 管理。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

2. 合理使用 profiles

Maven 的 profiles 可以让我们为不同环境(开发、测试、生产)配置不同的依赖和插件。例如,针对不同环境的数据库配置或构建参数。

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>development</env>
            <db.url>jdbc:mysql://localhost:3306/dev_db</db.url>
            <db.user>dev_user</db.user>
            <db.password>dev_password</db.password>
        </properties>
        <build>
        </build>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>production</env>
        </properties>
    </profile>
</profiles>

配置完 profiles 后,你可以通过命令行激活特定的构建环境。使用 -P 参数来指定要激活的 profile

  • 激活开发环境

    mvn clean install -Pdev
    
  • 激活生产环境

    mvn clean install -Pprod
    

在代码或配置文件中,你可以使用在 profiles 中定义的属性。例如,如果你在 Spring Boot 的 application.properties 中需要根据环境读取数据库配置,可以这样写:

spring.datasource.url=${db.url}
spring.datasource.username=${db.user}
spring.datasource.password=${db.password}

通过这种方式,Spring Boot 将根据激活的 profile 来加载相应的数据库配置。
当然你也可以创建不同的配置文件,

多环境配置文件激活属性
spring.profiles.active=dev                   加载application-dev.properties配置文件内容
application-dev.properties:                 开发环境
application-test.properties:                测试环境
application-prod.properties:                生产环境

3. 避免依赖冲突

Maven 通过依赖树解析依赖关系,当出现冲突时,可能会导致不同版本的 jar 包加载。使用 mvn dependency:tree 可以查看当前项目的依赖树,找到冲突点并通过 <exclusions> 标签排除不需要的依赖。

<dependency>
    <groupId>org.example</groupId>
    <artifactId>example-library</artifactId>
    <version>1.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.unwanted</groupId>
            <artifactId>unwanted-library</artifactId>
        </exclusion>
    </exclusions>
</dependency>

4. 优化插件配置与生命周期

通过优化插件配置可以加速构建和测试流程,例如跳过不必要的测试,或针对特定阶段配置行为。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
    </plugins>
</build>

三、项目案例分析

在这一部分,我们将结合多个模块的项目结构,进行深入的分析。项目包含了父工程(parent-project)、多个业务服务模块(如 service-aservice-b)、公共模块(commons)、以及几个扩展模块,如 API 网关模块、配置中心模块、集成测试模块和安全模块。

项目结构图

parent-project
│
├── commons (公共模块)
│      - 工具类
│      - DTO
│      - 常量
│
├── service-a (微服务A)
│      - 依赖 commons
│      - 业务逻辑
│
├── service-b (微服务B)
│      - 依赖 commons
│      - 业务逻辑
│
├── api-gateway (API 网关模块)
│      - 管理流量和路由
│
├── config-server (配置中心模块)
│      - 提供统一的配置管理
│
├── security (安全模块)
│      - 身份认证和授权管理
│
└── integration-tests (集成测试模块)
       - 测试跨服务和接口

这个结构清晰地展示了项目中不同模块之间的关系:

  • 父工程作为所有模块的管理者,统一配置依赖和插件。
  • 公共模块(commons) 封装了所有微服务所需的公共工具和逻辑。
  • 业务模块(service-a 和 service-b) 代表不同的微服务,处理各自的业务逻辑。
  • API 网关模块(api-gateway) 提供统一的流量和路由管理。
  • 配置中心模块(config-server) 集中管理微服务的配置。
  • 安全模块(security) 负责全局的身份认证与授权。
  • 集成测试模块(integration-tests) 则用于跨服务测试。

项目案例中的各模块配置

1. 父工程 parent-project

父工程主要用于统一管理依赖版本和插件配置。这里通过 dependencyManagement 来锁定各个依赖的版本,以确保所有子模块版本一致。

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.cloud</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>

    <modules>
        <module>commons</module>
        <module>service-a</module>
        <module>service-b</module>
        <module>api-gateway</module>
        <module>config-server</module>
        <module>security</module>
        <module>integration-tests</module>
    </modules>

    <properties>
        <java.version>11</java.version>
        <spring.boot.version>2.5.4</spring.boot.version>
        <spring.cloud.version>2020.0.3</spring.cloud.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Spring Boot BOM -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!-- Spring Cloud BOM -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring.cloud.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

2. 公共模块 commons

公共模块封装了项目中可以被多个服务模块复用的工具类、常量、DTO(数据传输对象)等内容。

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>commons</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <!-- 常用工具类 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>
    </dependencies>
</project>

3. 业务模块 service-aservice-b

这两个模块都依赖公共模块 commons,并根据需要引入其他依赖来实现自己的业务逻辑。

service-apom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>service-a</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>com.example.cloud</groupId>
            <artifactId>commons</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

service-b 的配置类似,不再赘述。

4. API 网关模块 api-gateway

此模块用于管理 API 流量和路由,通常采用 Spring Cloud Gateway 实现。

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>api-gateway</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
    </dependencies>
</project>

5. 配置中心模块 config-server

此模块负责集中管理各微服务的配置。

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>config-server</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
    </dependencies>
</project>

6. 安全模块 security

此模块为项目提供认证和授权服务。

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>security</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>
</project>

7. 集成测试模块 integration-tests

集成测试模块用于跨模块和接口的集成测试。

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example.cloud</groupId>
        <artifactId>parent-project</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.example.cloud</groupId>
    <artifactId>integration-tests</artifactId>
    <version>1.0.0</version>
    <packaging>jar

</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

总结

该项目案例展示了一个典型的微服务架构项目,涵盖了多种类型的模块配置,从业务服务到基础架构模块,以及一些扩展功能模块如安全和集成测试。通过统一的 parent-project 管理,所有模块共享一致的依赖版本和配置,从而提升了项目的可维护性和扩展性。

四、总结补充

Maven 是企业级开发中不可或缺的工具,通过精心配置 pom.xml,你可以显著提高项目管理的效率、减少冲突并提升构建速度。建议在大型项目中使用 dependencyManagement 统一依赖版本、优化插件配置、以及合理使用 profiles 以应对不同环境的需求。

在实践中,企业级开发可能还会涉及以下几点:

  • CI/CD 集成:将 Maven 与 Jenkins 或 GitLab CI 等工具集成,实现自动化构建和部署。
  • 多模块项目的优化:对于微服务项目,建议使用父 POM 管理公共依赖,子模块根据需要引入特定依赖。
  • 性能优化:使用插件如 maven-shade-pluginmaven-assembly-plugin,可以打包整个项目成单个可执行文件,适合容器化部署。

通过这些技巧,你可以最大化利用 Maven 的能力,为项目开发带来高效与稳定。

五、常用依赖

一些常用的额外依赖:

<dependencies>
    <!-- Lombok,用于简化类的书写 -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>
    
    <!-- Spring Boot Starter Data JPA,用于数据库访问 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <!-- MySQL Connector,用于连接 MySQL 数据库 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <!-- SLF4J,提供日志抽象层 -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    
    <!-- JJWT,用于处理 JSON Web Token -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.1</version>
    </dependency>
    
    <!-- Spring Cloud Alibaba Nacos Discovery -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    
    <!-- Spring Cloud Alibaba Nacos Config -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    
    <!-- Spring Cloud OpenFeign -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    
    <!-- Spring Cloud LoadBalancer -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    
    <!-- Spring Cloud Alibaba Sentinel -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    
    <!-- Spring Cloud Gateway -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
</dependencies>

依赖详细说明

  1. Lombok

    • 作用:通过注解生成 getters、setters、构造函数等,减少样板代码。
    • 使用场景:在实体类和数据传输对象(DTO)中使用,提升代码可读性和可维护性。
  2. Spring Boot Starter Data JPA

    • 作用:集成 Spring Data JPA,简化数据库操作。
    • 使用场景:在需要与数据库进行 CRUD 操作的项目中使用,支持 JPA Repository 接口。
  3. MySQL Connector

    • 作用:提供 MySQL 数据库的 JDBC 驱动。
    • 使用场景:在使用 MySQL 数据库时必不可少,用于数据源配置。
  4. SLF4J

    • 作用:提供日志记录的统一接口,可以与多种日志框架(如 Logback、Log4j)结合使用。
    • 使用场景:需要记录应用日志时使用,方便切换不同的日志实现。
  5. JJWT

    • 作用:用于创建和验证 JSON Web Token (JWT),支持无状态的身份认证。
    • 使用场景:在需要用户认证和授权的应用中使用,尤其是微服务架构下。
  6. Spring Cloud Alibaba Nacos Discovery

    • 作用:提供服务注册与发现功能。
    • 使用场景:在微服务架构中使用,允许服务实例自动注册到 Nacos,其他服务可以通过 Nacos 查找。
  7. Spring Cloud Alibaba Nacos Config

    • 作用:支持从 Nacos 获取外部配置。
    • 使用场景:在需要动态配置的应用中使用,允许在运行时修改配置而无需重启服务。
  8. Spring Cloud OpenFeign

    • 作用:简化服务间调用,提供声明式 HTTP 客户端功能。
    • 使用场景:在微服务间需要频繁调用其他服务时使用,避免手动编写 REST 调用代码。
  9. Spring Cloud LoadBalancer

    • 作用:实现客户端负载均衡。
    • 使用场景:在需要调用多个服务实例的情况下使用,确保请求的均匀分配。
  10. Spring Cloud Alibaba Sentinel

    • 作用:实现流量控制、熔断和降级。
    • 使用场景:在关键服务中使用,增强系统的稳定性和容错能力。
  11. Spring Cloud Gateway

    • 作用:提供 API 网关功能,支持路由、过滤等。
    • 使用场景:在微服务架构中作为入口点,处理请求路由和过滤。

当然MyBatis也是常用的,

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
</dependency>

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.3.4</version>
</dependency>

可以进我的主页:胡耀超的博客 搜索MyBatis(或者查看java专栏,不单单是MyBatis),即可从入门到精通!

当然你也可以把你常用依赖放到评论区里,以便后续查看和交流!

标签:依赖,进阶,spring,Maven,详解,模块,org,com,cloud
From: https://blog.csdn.net/hyc010110/article/details/142410741

相关文章

  • C语言指针详解与应用
    C语言指针1.指针简介指针与底层硬件紧密联系,使用指针可操作数据地址,实现数据的间接访问2.计算机存储机制在C语言中内存的分配是以一个字节为单位进行线性分配且每个字节都会对应的地址inta=0x12345678;shortb=0x5A6B;charc[]={0x33,0x34,0x35};**int......
  • 全面解析 JDK17新特性:密封类、模式匹配、文本块、垃圾回收等最新功能详解
    引言JDK17作为Java的长期支持(LTS)版本,引入了许多新特性和改进,这些更新不仅提升了代码的可读性和可维护性,还增强了性能。本文将详细探讨JDK17的关键新特性,包括密封类、模式匹配、文本块、增强的垃圾回收机制等,并附上代码示例,帮助你更好地理解和应用这些特性。1.密封......
  • Nginx配置详解
    #nginx进程数,建议设置为等于CPU总核心数。worker_processes1;#事件区块开始events{#单个进程最大连接数(最大连接数=连接数*进程数)#根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每台nginx服务器的最大连......
  • Java免税商品购物商城:Spring Boot实现详解
    第一章绪论1.1课题开发的背景从古至今,通过书本获取知识信息的方式完全被互联网络信息化,但是免税商品优选购物商城,对于购物商城工作来说,仍然是一项非常重要的工作。尤其是免税商品优选购物商城,传统人工记录模式已不符合当前社会发展和信息管理工作需求。对于仓储信息管理......
  • 2025届必看:Java SpringBoot搭建大学生资助管理系统,详解功能模块,实现学生信息高效管理!
    ✍✍计算机毕业编程指导师**⭐⭐个人介绍:自己非常喜欢研究技术问题!专业做Java、Python、小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。⛽⛽实战项目:有源码或者技术上的问题欢迎在评论区一起讨论交流!⚡⚡Java、Python、微信小程序、大数据实战项目集⚡⚡文末......
  • 提升数字化校园管理效率:资产领用功能详解
    在现代教育领域,数字化校园资产管理系统已成为提高学校运营效率和资产利用率的关键手段。其中,资产领用功能作为数字化校园管理系统的核心功能之一,扮演着重要的角色。本文将为您介绍数字化校园资产管理中的资产领用功能,帮助您深入了解其作用和优势。数字化校园资产管理系统的资产领用......
  • Vue3 之hooks 使用详解教程
    一、基本使用<template><view>{{params}}<button@click="goUrl('/pages/index/index')">跳转</button></view></template><script>import{ref,onMounted......
  • Python 中的 strip() 和 split() 方法详解
    目录一、strip()方法1.什么是strip()?2.基本语法3.基本用法示例1)去除空白字符2)移除指定字符4.lstrip()和rstrip()5.注意事项二、split()方法1.什么是split()?2.基本语法3.基本用法示例1)按空格分割字符串2)指定分隔符3)限制分割次数4.rsplit()方法......
  • Scala安装与环境配置详解教程
    本文参考来源:http://mengmianren.com/zhihuishu2020/641069.html Scala运行在java的JVM之上,因此需要先安装Java运行环境一、JDK8的下载和安装及环境变量配置使用的jdk版本是:jdk-8u191-windows-i586.exehttps://pan.baidu.com/s/1RNNb7lcqKHC_2h0iiTlqFg?pwd=9t5e提取码:9t5......
  • Java流程控制语句——条件控制语句详解(附有流程图)
    在Java编程中,条件控制语句用于控制程序的执行路径,决定根据某些条件来选择执行某段代码或跳过某段代码。它们是Java编程的重要组成部分,帮助开发者根据不同的输入、状态或数据流来编写更加灵活和动态的代码。在本文中,我们将详细讲解Java中的几种条件控制语句:if-else、else......