从环境搭建到权限控制:SpringBoot Web 应用开发全流程实战指南

SpringBoot+Vue微人事管理系统实战:从环境搭建到部署运维 微服务架构通过将单一应用拆分为多个独立服务,实现了业务模块的解耦和独立部署。其核心原理是基于轻量级通信协议进行服务间调用,配合容器化技术提升系统弹性。在企业级应用开发中,这种架构能够显著提高开发效率和系统可维护性,特别适合人事管理等复杂业务场景。以SpringBoot作为后端框架,结合Vue.js前端技术,可以快速构建前后端分离的微人事管理系统。该系统通过RBAC权限控制和RESTful API设计,实现了员工信息管理、考勤统计等核心功能,为企业数字化转型提供完整的技术解决方案。 阅读详情

从环境搭建到权限控制:SpringBoot Web 应用开发全流程实战指南

一、前言

在当前的软件开发领域,Web 应用因其跨平台、易访问的特性,成为企业数字化转型的核心载体。而 SpringBoot 作为 Spring 生态的明星项目,以 “约定优于配置” 的设计理念,极大简化了 Web 应用的开发流程,降低了框架整合的复杂度,成为 Java 开发者构建 Web 应用的首选框架。

本文基于 Web 应用项目开发的核心流程,从开发环境搭建、SpringBoot 项目初始化、持久层框架整合、数据缓存优化、视图层开发到权限安全控制,进行全方位、手把手的实战讲解。内容涵盖项目开发的关键技术点,包含详细的操作步骤、代码示例、问题排查方案及图文说明,旨在帮助开发者快速掌握 SpringBoot Web 应用的开发技巧,同时满足 CSDN 博客原创、图文并茂的要求,为课程学习提供实用的技术参考。

本文适用于 Java 初学者、Web 应用开发入门者及需要巩固 SpringBoot 核心技术的开发者,所有操作均经过实际验证,确保步骤可复现、代码可运行。

二、开发环境配置:筑牢项目开发基石

开发环境的稳定性直接影响项目开发效率,Web 应用开发需重点配置 JDK、Maven、IDEA 三大核心工具,三者的版本兼容性及配置合理性是后续开发的关键。本节将详细讲解各工具的下载、安装、配置及验证流程。

2.1 JDK 安装与配置(版本:JDK 17)

JDK(Java Development Kit)是 Java 开发的核心工具包,提供了编译、运行 Java 程序的基础环境。SpringBoot 3.x 版本要求 JDK 最低版本为 17,因此选择 JDK 17 作为开发环境。

2.1.1 JDK 下载
  1. 访问 Oracle 官网 JDK 下载页面(https://www.oracle.com/java/technologies/downloads/#java17),选择对应操作系统的安装包(Windows 系统选择.exe 文件,macOS 选择.dmg 文件)。
  2. 需登录 Oracle 账号后下载,若无账号可注册免费账号,或通过国内镜像站点(如华为云、阿里云)下载,避免官网下载速度慢的问题。【图 2-1 JDK 17 下载页面截图】(标注:红框选中 Windows x64 Installer 下载链接)
2.1.2 JDK 安装
  1. 双击下载的安装包,启动安装向导,点击 “下一步”。
  2. 选择安装路径(建议自定义路径,避免中文和空格,例如:D:\Develop\Java\jdk-17.0.10),点击 “下一步”。
  3. 等待安装完成,无需勾选 “安装 JRE”(JDK 17 已集成 JRE),点击 “关闭”。【图 2-2 JDK 安装路径选择截图】(标注:自定义路径输入框及 “下一步” 按钮)
2.1.3 环境变量配置(Windows 系统)
  1. 右键点击 “此电脑”→“属性”→“高级系统设置”→“环境变量”,在 “系统变量” 中添加以下配置:
    • 变量名:JAVA_HOME,变量值:D:\Develop\Java\jdk-17.0.10(JDK 安装路径)
    • 变量名:CLASSPATH,变量值:.;% JAVA_HOME%\lib\dt.jar;% JAVA_HOME%\lib\tools.jar(注意开头的 “.;” 不可省略)
    • 编辑 “Path” 变量,添加两个路径:% JAVA_HOME%\bin 和 % JAVA_HOME%\jre\bin【图 2-3 环境变量配置截图】(标注:JAVA_HOME、CLASSPATH 变量配置及 Path 变量编辑界面)
2.1.4 安装验证
  1. 按下 Win+R 键,输入 cmd 打开命令提示符,执行以下命令:
    • java -version:若输出 “java version "17.0.10" 2024-01-16 LTS” 等类似信息,说明 JDK 版本正确。
    • javac:若输出 javac 的命令用法说明,说明环境变量配置成功。【图 2-4 JDK 验证结果截图】(标注:java -version 和 javac 命令的执行输出)
2.1.5 常见问题排查
  • 问题 1:执行 java -version 提示 “不是内部或外部命令”?解决方案:检查 JAVA_HOME 路径是否正确,Path 变量是否添加了 % JAVA_HOME%\bin,配置完成后需重启命令提示符。
  • 问题 2:安装后提示 “找不到 jre 目录”?解决方案:JDK 17 默认集成 JRE,若未显示 jre 目录,可在 JDK 安装路径下执行命令:bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre。

2.2 Maven 安装与配置(版本:3.8.8)

Maven 是 Java 项目的依赖管理和构建工具,用于自动下载项目所需依赖包、编译项目、打包部署等。选择与 JDK 17 兼容的 Maven 3.8.8 版本。

2.2.1 Maven 下载
  1. 访问 Maven 官网(https://maven.apache.org/download.cgi),下载 Binary zip archive 版本(如 apache-maven-3.8.8-bin.zip)。
  2. 解压到自定义路径(避免中文和空格,例如:D:\Develop\apache-maven-3.8.8)。【图 2-5 Maven 下载页面截图】(标注:Binary zip archive 下载链接)
2.2.2 环境变量配置
  1. 打开 “环境变量”,在 “系统变量” 中添加:
    • 变量名:MAVEN_HOME,变量值:D:\Develop\apache-maven-3.8.8
    • 编辑 “Path” 变量,添加:% MAVEN_HOME%\bin【图 2-6 Maven 环境变量配置截图】(标注:MAVEN_HOME 变量及 Path 变量添加内容)
2.2.3 settings.xml 配置(核心步骤)

settings.xml 是 Maven 的核心配置文件,用于配置镜像源、本地仓库、JDK 版本等,需修改以下关键配置:

【图 2-7 settings.xml 配置截图】(标注:本地仓库、阿里云镜像、JDK 配置区域)

2.2.4 安装验证

2.3 IDEA 配置(版本:IntelliJ IDEA 2023.2)

IntelliJ IDEA 是 Java 开发的主流 IDE,提供了强大的代码编辑、调试、项目管理功能,需配置 JDK 和 Maven,确保与本地环境一致。

2.3.1 IDEA 下载与安装

2.3.2 IDEA 全局配置(JDK 与 Maven)

2.3.3 实用插件推荐

安装以下插件可提升开发效率:

三、快速搭建 SpringBoot 项目:从零到一初始化

SpringBoot 提供了便捷的项目初始化方式,支持通过网页版 Spring Initializr 或 IDEA 内置工具快速创建项目,自动引入核心依赖和配置文件,无需手动整合 Spring 框架组件。

3.1 项目初始化方式一:Spring Initializr 网页版

3.1.1 访问网页版初始化工具

3.1.2 配置项目基本信息

3.1.3 选择核心依赖

在 Dependencies 搜索框中添加以下依赖(Web 应用开发必备):

3.1.4 生成项目并解压

3.2 项目初始化方式二:IDEA 内置工具

3.2.1 新建 SpringBoot 项目

3.3 项目结构解析

SpringBoot 项目采用约定优于配置的目录结构,核心目录如下(以 IDEA 中显示为例):

plaintext

springboot-web-demo/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── example/
│   │   │           └── springbootwebdemo/
│   │   │               ├── SpringbootWebDemoApplication.java  // 项目启动类
│   │   │               ├── controller/  // 控制器层(处理HTTP请求)
│   │   │               ├── service/     // 服务层(业务逻辑处理)
│   │   │               ├── mapper/      // 持久层(数据访问)
│   │   │               ├── entity/      // 实体类(与数据库表对应)
│   │   │               ├── config/      // 配置类(框架配置、自定义配置)
│   │   │               ├── util/        // 工具类
│   │   │               └── exception/   // 异常处理
│   │   └── resources/
│   │       ├── application.yml         // 核心配置文件(推荐.yml格式,更简洁)
│   │       ├── application-dev.yml     // 开发环境配置(多环境配置)
│   │       ├── application-prod.yml    // 生产环境配置(多环境配置)
│   │       ├── static/                 // 静态资源目录(CSS、JS、图片等)
│   │       └── templates/              // 模板文件目录(Thymeleaf模板)
│   └── test/                           // 测试类目录
├── pom.xml                             // Maven依赖配置文件
└── README.md                           // 项目说明文档

【图 3-4 项目目录结构截图】(标注:核心目录及文件)

3.4 项目启动与验证

3.4.1 启动项目

3.4.2 验证启动成功

3.5 核心配置文件:application.yml

SpringBoot 的配置文件支持.yml 和.properties 格式,推荐使用.yml,语法更简洁、层次更清晰。以下是基础配置示例:

yaml

# 应用基础配置
spring:
  application:
    name: springboot-web-demo  # 应用名称
  # 多环境配置激活(默认激活开发环境)
  profiles:
    active: dev

# 服务器配置
server:
  port: 8080  # 端口号,若8080被占用可修改为8081、8090等
  servlet:
    context-path: /  # 应用访问路径,默认/,可修改为/ demo等

开发环境配置文件 application-dev.yml:

yaml

# 开发环境数据库配置
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/springboot_web_demo?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root  # 数据库用户名
    password: root  # 数据库密码
    driver-class-name: com.mysql.cj.jdbc.Driver
  # Redis配置
  redis:
    host: localhost
    port: 6379
    password:  # Redis密码,默认无
    database: 0  # 操作的Redis数据库索引(0-15)
  # Thymeleaf配置
  thymeleaf:
    prefix: classpath:/templates/  # 模板文件前缀
    suffix: .html  # 模板文件后缀
    mode: HTML5  # 模板模式
    cache: false  # 开发环境关闭缓存,修改模板后无需重启项目

# MyBatis-Plus配置
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml  # Mapper XML文件路径
  type-aliases-package: com.example.springbootwebdemo.entity  # 实体类别名包
  configuration:
    map-underscore-to-camel-case: true  # 下划线转驼峰命名
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  # 打印SQL日志

【图 3-8 配置文件截图】(标注:application.yml 和 application-dev.yml 的配置内容)

3.6 常见问题排查

四、SpringBoot 整合 MyBatis-Plus:高效操作数据库

MyBatis-Plus(简称 MP)是 MyBatis 的增强工具,在 MyBatis 的基础上提供了 CRUD 接口封装、代码生成、分页插件等功能,无需编写大量 XML 文件,极大简化了持久层开发。本节将讲解 SpringBoot 与 MyBatis-Plus 的整合流程,包括数据库设计、实体类编写、Mapper 层实现、CRUD 操作及高级功能使用。

4.1 前期准备:创建数据库与表

4.1.1 安装 MySQL(版本:8.0.35)

4.1.2 创建数据库与测试表

【图 4-2 数据库表创建截图】(标注:SQL 执行结果、sys_user 表结构)

4.2 整合 MyBatis-Plus 核心步骤

4.2.1 确认依赖引入

在 pom.xml 中已通过 Spring Initializr 引入 MyBatis-Plus Starter 依赖,无需手动添加:

xml

<!-- MyBatis-Plus Starter -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.5</version>
</dependency>
<!-- MySQL Driver -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>
<!-- Lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>

【图 4-3 pom.xml 依赖截图】(标注:MyBatis-Plus 相关依赖)

4.2.2 编写实体类 SysUser

使用 Lombok 的 @Data 注解简化代码,通过 MyBatis-Plus 的 @TableName、@TableId 等注解映射数据库表和字段:

java

运行

package com.example.springbootwebdemo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * 系统用户实体类
 */
@Data  // Lombok注解,自动生成getter、setter、toString等方法
@TableName("sys_user")  // 映射数据库表名
public class SysUser {
    @TableId(type = IdType.AUTO)  // 主键策略:自增
    private Long id;  // 用户ID

    private String username;  // 用户名(与表中字段名一致,无需额外注解)

    private String password;  // 密码

    private String nickname;  // 昵称

    private String email;  // 邮箱

    private String phone;  // 手机号

    private Integer status;  // 状态:0-禁用,1-正常

    private LocalDateTime createTime;  // 创建时间

    private LocalDateTime updateTime;  // 更新时间
}

【图 4-4 实体类 SysUser 截图】(标注:Lombok 注解和 MyBatis-Plus 注解)

4.2.3 编写 Mapper 接口 SysUserMapper

继承 MyBatis-Plus 的 BaseMapper 接口,BaseMapper 已封装了 CRUD 核心方法(selectById、selectList、insert、updateById、removeById 等),无需编写 XML 文件即可实现基础操作:

java

运行

package com.example.springbootwebdemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springbootwebdemo.entity.SysUser;
import org.springframework.stereotype.Repository;

/**
 * 用户Mapper接口
 */
@Repository  // 标识为持久层组件,让Spring扫描到
public interface SysUserMapper extends BaseMapper<SysUser> {
    // 基础CRUD方法已通过BaseMapper继承,无需手动编写
    // 若需自定义查询,可在此处添加方法,在XML文件中编写SQL
}

【图 4-5 Mapper 接口截图】(标注:继承 BaseMapper 接口)

4.2.4 编写 Service 层

Service 层用于封装业务逻辑,分为接口和实现类,通过依赖注入 Mapper 接口实现数据访问。

4.2.4.1 Service 接口 SysUserService

继承 MyBatis-Plus 的 IService 接口,IService 提供了更丰富的 CRUD 方法(如 list、page、saveOrUpdate 等):

java

运行

package com.example.springbootwebdemo.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.springbootwebdemo.entity.SysUser;

/**
 * 用户Service接口
 */
public interface SysUserService extends IService<SysUser> {
    // 可添加自定义业务方法
}
4.2.4.2 Service 实现类 SysUserServiceImpl

继承 MyBatis-Plus 的 ServiceImpl 类,实现 SysUserService 接口,通过 @Autowired 注入 Mapper 接口:

java

运行

package com.example.springbootwebdemo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springbootwebdemo.entity.SysUser;
import com.example.springbootwebdemo.mapper.SysUserMapper;
import com.example.springbootwebdemo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户Service实现类
 */
@Service  // 标识为服务层组件
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    // 基础业务方法已通过ServiceImpl继承,可重写或添加自定义方法
}

【图 4-6 Service 层代码截图】(标注:Service 接口与实现类的继承关系)

4.2.5 配置 MyBatis-Plus 分页插件

MyBatis-Plus 提供了内置的分页插件,需编写配置类启用:

java

运行

package com.example.springbootwebdemo.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MyBatis-Plus配置类
 */
@Configuration  // 标识为配置类
public class MyBatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加MySQL分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

【图 4-7 分页插件配置截图】(标注:@Bean 注解和分页插件实例化)

4.3 CRUD 操作实战

通过 Controller 层调用 Service 层方法,实现用户的增删改查操作,编写测试接口:

4.3.1 编写 SysUserController

java

运行

package com.example.springbootwebdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springbootwebdemo.entity.SysUser;
import com.example.springbootwebdemo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户Controller,处理用户相关HTTP请求
 */
@RestController  // 标识为REST接口控制器,返回JSON数据
@RequestMapping("/user")  // 接口统一前缀
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据ID查询用户
     */
    @GetMapping("/{id}")
    public SysUser getUserById(@PathVariable Long id) {
        return sysUserService.getById(id);
    }

    /**
     * 查询所有用户
     */
    @GetMapping("/list")
    public List<SysUser> getUserList() {
        return sysUserService.list();
    }

    /**
     * 分页查询用户
     */
    @GetMapping("/page")
    public IPage<SysUser> getUserPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<SysUser> page = new Page<>(pageNum, pageSize);
        return sysUserService.page(page);
    }

    /**
     * 添加用户
     */
    @PostMapping
    public boolean addUser(@RequestBody SysUser sysUser) {
        return sysUserService.save(sysUser);
    }

    /**
     * 修改用户
     */
    @PutMapping
    public boolean updateUser(@RequestBody SysUser sysUser) {
        return sysUserService.updateById(sysUser);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/{id}")
    public boolean deleteUser(@PathVariable Long id) {
        return sysUserService.removeById(id);
    }
}

【图 4-8 SysUserController 截图】(标注:各接口注解、参数传递方式)

4.3.2 接口测试(使用 Postman)

4.3.3 控制台 SQL 日志查看

由于在 application-dev.yml 中配置了 mybatis-plus.configuration.log-impl,控制台会打印执行的 SQL 语句,便于调试:

plaintext

==>  Preparing: SELECT id,username,password,nickname,email,phone,status,create_time,update_time FROM sys_user LIMIT ?,?
==> Parameters: 0(Long), 5(Long)
<==      Total: 2

【图 4-10 SQL 日志截图】(标注:执行的 SQL 语句和参数)

4.4 MyBatis-Plus 高级功能:条件构造器

MyBatis-Plus 的 QueryWrapper 用于构建复杂查询条件,无需编写 XML 文件,示例如下:

java

运行

/**
 * 条件查询:查询状态为1且昵称包含"用户"的用户
 */
@GetMapping("/list/condition")
public List<SysUser> getUserByCondition() {
    QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("status", 1)  // 等于
               .like("nickname", "用户");  // 模糊查询
    return sysUserService.list(queryWrapper);
}

测试该接口,控制台打印的 SQL 语句为:

plaintext

SELECT id,username,password,nickname,email,phone,status,create_time,update_time FROM sys_user WHERE (status = ? AND nickname LIKE ?)
Parameters: 1(Integer), %用户%(String)

【图 4-11 条件构造器测试截图】(标注:QueryWrapper 构建条件、响应结果)

4.5 常见问题排查

五、数据缓存管理:Spring Cache+Redis 优化性能

在 Web 应用中,频繁查询数据库会导致系统性能下降,缓存是解决该问题的核心方案。Spring Cache 提供了统一的缓存抽象,支持多种缓存实现(如 Redis、Ehcache),结合 Redis(高性能键值对数据库)可实现分布式缓存,本节讲解 SpringBoot 整合 Spring Cache+Redis 的完整流程。

5.1 Redis 安装与启动(Windows 系统)

5.1.1 Redis 下载

5.1.2 启动 Redis 服务

5.1.3 验证 Redis 连接

5.2 SpringBoot 整合 Spring Cache+Redis

5.2.1 引入核心依赖

在 pom.xml 中已通过 Spring Initializr 引入 Redis Starter 和 Spring Cache 依赖:

xml

<!-- Spring Cache -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- Redis Starter -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

【图 5-4 缓存相关依赖截图】(标注:Spring Cache 和 Redis 依赖)

5.2.2 配置 Redis 与缓存

在 application-dev.yml 中配置 Redis 连接信息和缓存规则:

yaml

spring:
  # Redis配置
  redis:
    host: localhost  # Redis服务地址
    port: 6379       # Redis端口
    password:        #  Redis密码(默认无)
    database: 0      # 操作的数据库索引
    timeout: 10000   # 连接超时时间(毫秒)
    lettuce:
      pool:
        max-active: 8  # 最大连接数
        max-idle: 8    # 最大空闲连接数
        min-idle: 2    # 最小空闲连接数
  # Spring Cache配置
  cache:
    type: redis  # 缓存类型为Redis
    redis:
      time-to-live: 3600000  # 缓存过期时间(1小时,单位毫秒)
      cache-null-values: false  # 不缓存null值
      key-prefix: "cache:"  # 缓存key前缀

【图 5-5 Redis 与缓存配置截图】(标注:核心配置项)

5.2.3 启用缓存注解

在 SpringBoot 启动类上添加 @EnableCaching 注解,启用 Spring Cache 功能:

java

运行

package com.example.springbootwebdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@SpringBootApplication
@EnableCaching  // 启用缓存注解
public class SpringbootWebDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootWebDemoApplication.class, args);
    }

}

【图 5-6 启动类启用缓存截图】(标注:@EnableCaching 注解)

5.2.4 自定义缓存序列化配置

默认情况下,Spring Cache 使用 JdkSerializationRedisSerializer 序列化缓存数据,序列化后的数据可读性差,需自定义序列化方式(使用 Jackson2JsonRedisSerializer):

java

运行

package com.example.springbootwebdemo.config;

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Duration;

/**
 * Redis缓存配置类(自定义序列化)
 */
@Configuration
@EnableCaching
public class RedisCacheConfig {

    @Bean
    public RedisCacheManager redisCacheManager(RedisConnectionFactory factory) {
        // 1. 配置Jackson序列化器
        Jackson2JsonRedisSerializer<Object> jacksonSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
        ObjectMapper objectMapper = new ObjectMapper();
        // 设置访问权限,允许访问所有字段
        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        // 启用Jackson的默认类型识别机制(解决反序列化时类型转换问题)
        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
        jacksonSerializer.setObjectMapper(objectMapper);

        // 2. 配置缓存序列化规则
        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.hours(1))  // 缓存过期时间1小时
                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))  // key序列化方式:String
                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jacksonSerializer))  // value序列化方式:Jackson
                .disableCachingNullValues();  // 不缓存null值

        // 3. 创建RedisCacheManager
        return RedisCacheManager.builder(factory)
                .cacheDefaults(config)
                .build();
    }
}

【图 5-7 缓存序列化配置截图】(标注:Jackson 序列化器配置、缓存规则设置)

5.3 缓存注解实战

Spring Cache 提供了多个核心注解,用于实现缓存的增删改查,本节结合用户查询功能讲解注解使用。

5.3.1 @Cacheable:查询缓存

在查询方法上添加 @Cacheable 注解,首次查询时从数据库获取数据并存入缓存,后续查询直接从缓存获取,无需访问数据库。修改 SysUserService 接口的 getById 方法:

java

运行

/**
 * 根据ID查询用户,缓存key为"user:{id}"
 */
@Cacheable(value = "user", key = "#id")  // value:缓存名称,key:缓存键(使用SpEL表达式)
@Override
public SysUser getById(Long id) {
    System.out.println("从数据库查询用户,ID:" + id);
    return sysUserMapper.selectById(id);
}
5.3.2 @CacheEvict:删除缓存

在删除或修改方法上添加 @CacheEvict 注解,删除对应的缓存,确保缓存数据与数据库一致。修改 SysUserService 接口的 removeById 方法:

java

运行

/**
 * 删除用户,删除缓存中key为"user:{id}"的数据
 */
@CacheEvict(value = "user", key = "#id")  // 删除指定key的缓存
@Override
public boolean removeById(Long id) {
    System.out.println("删除数据库用户,ID:" + id);
    return sysUserMapper.deleteById(id) > 0;
}
5.3.3 @CachePut:更新缓存

在更新方法上添加 @CachePut 注解,更新数据库数据后同步更新缓存。修改 SysUserService 接口的 updateById 方法:

java

运行

/**
 * 更新用户,同步更新缓存中key为"user:{entity.id}"的数据
 */
@CachePut(value = "user", key = "#entity.id")  // 更新指定key的缓存
@Override
public boolean updateById(SysUser entity) {
    System.out.println("更新数据库用户,ID:" + entity.getId());
    return sysUserMapper.updateById(entity) > 0;
}
5.3.4 @CacheConfig:统一配置缓存

在 Service 接口上添加 @CacheConfig 注解,统一配置缓存名称,避免在每个方法上重复编写 value 属性:

java

运行

@Service
@CacheConfig(cacheNames = "user")  // 统一缓存名称为"user"
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    // 后续方法可省略value属性,如@Cacheable(key = "#id")
}

5.4 缓存效果验证

5.4.1 测试 @Cacheable 注解

5.4.2 测试 @CacheEvict 注解

5.5 缓存优化建议

5.6 常见问题排查

六、Thymeleaf 视图开发:构建动态 Web 页面

Thymeleaf 是 SpringBoot 推荐的视图层模板引擎,支持 HTML 原型开发,无需额外标签库,语法简洁,可与 SpringBoot 无缝整合。本节讲解 Thymeleaf 的核心语法及实战案例,实现用户列表和详情页面的动态渲染。

6.1 Thymeleaf 基础配置

6.1.1 确认依赖引入

在 pom.xml 中已引入 Thymeleaf 依赖:

xml

<!-- Thymeleaf -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
6.1.2 配置文件优化

在 application-dev.yml 中已配置 Thymeleaf 核心参数,开发环境关闭缓存:

yaml

spring:
  thymeleaf:
    prefix: classpath:/templates/  # 模板文件存放路径
    suffix: .html  # 模板文件后缀
    mode: HTML5  # 模板模式
    encoding: UTF-8  # 编码格式
    cache: false  # 开发环境关闭缓存

6.2 Thymeleaf 核心语法

Thymeleaf 通过 “th:” 前缀标签实现动态数据绑定,核心语法包括变量输出、循环、条件判断、路径跳转等,以下是常用语法详解。

6.2.1 变量输出:th:text、th:value

html

预览

<!-- 输出用户昵称,转义特殊字符 -->
<h1 th:text="${user.nickname}">默认昵称</h1>

<!-- 表单输入框绑定用户名 -->
<input type="text" name="username" th:value="${user.username}">
6.2.2 循环:th:each

用于遍历集合数据(如列表、数组),常用变量:

html

预览

<!-- 遍历用户列表 -->
<table>
    <tr>
        <<th>序号</</th>
        <<th>用户名</</th>
        <<th>昵称</</th>
        <<th>状态</</th>
    </tr>
    <tr th:each="user, status : ${userList}">
        <td th:text="${status.count}"></td>
        <td th:text="${user.username}"></td>
        <td th:text="${user.nickname}"></td>
        <td th:text="${user.status == 1 ? '正常' : '禁用'}"></td>
    </tr>
</table>
6.2.3 条件判断:th:if、th:unless

html

预览

<!-- 状态为1时显示"正常",否则显示"禁用" -->
<span th:if="${user.status == 1}" style="color: green;">正常</span>
<span th:unless="${user.status == 1}" style="color: red;">禁用</span>
6.2.4 路径跳转:th:href、th:action

html

预览

<!-- 跳转到用户详情页,传递ID参数 -->
<a th:href="@{/user/detail(id=${user.id})}">查看详情</a>

<!-- 表单提交到用户更新接口 -->
<form th:action="@{/user/update}" method="post">
    <!-- 表单内容 -->
</form>
6.2.5 模板布局:th:fragment、th:replace

用于抽取页面公共部分(如页眉、页脚、导航栏),实现代码复用。

html

预览

<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>公共布局</title>
    <!-- 引入CSS、JS等公共资源 -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
    <!-- 页眉 -->
    <header th:fragment="header">
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <div class="container">
                <a class="navbar-brand" href="/">SpringBoot Web Demo</a>
                <div class="collapse navbar-collapse">
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item">
                            <a class="nav-link" th:href="@{/user/list}">用户管理</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <!-- 页脚 -->
    <footer th:fragment="footer" class="mt-5 bg-light py-3">
        <div class="container text-center">
            <p>© 2024 SpringBoot Web应用开发实战</p>
        </div>
    </footer>
</body>
</html>

html

预览

<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
</head>
<body>
    <!-- 引用页眉 -->
    <div th:replace="common/layout :: header"></div>

    <!-- 页面主体内容 -->
    <div class="container mt-3">
        <h2>用户列表</h2>
        <!-- 用户列表表格 -->
    </div>

    <!-- 引用页脚 -->
    <div th:replace="common/layout :: footer"></div>
</body>
</html>

6.3 实战:用户列表与详情页面

6.3.1 编写 Controller 层方法

创建 UserViewController,返回 Thymeleaf 模板页面:

java

运行

package com.example.springbootwebdemo.controller;

import com.example.springbootwebdemo.entity.SysUser;
import com.example.springbootwebdemo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 用户视图控制器,返回Thymeleaf页面
 */
@Controller
@RequestMapping("/user/view")
public class UserViewController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户列表页面
     */
    @GetMapping("/list")
    public String userList(Model model) {
        // 查询所有用户,存入Model(用于页面渲染)
        List<SysUser> userList = sysUserService.list();
        model.addAttribute("userList", userList);
        return "user/userList";  // 返回templates/user/userList.html模板
    }

    /**
     * 用户详情页面
     */
    @GetMapping("/detail/{id}")
    public String userDetail(@PathVariable Long id, Model model) {
        // 根据ID查询用户
        SysUser user = sysUserService.getById(id);
        model.addAttribute("user", user);
        return "user/userDetail";  // 返回templates/user/userDetail.html模板
    }
}

【图 6-1 UserViewController 截图】(标注:Model 数据传递、模板返回路径)

6.3.2 编写用户列表页面(userList.html)

html

预览

<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <!-- 引入Bootstrap样式,简化页面布局 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
    <!-- 引用公共页眉 -->
    <div th:replace="common/layout :: header"></div>

    <!-- 页面主体 -->
    <div class="container mt-4">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h2>用户管理</h2>
            <a href="#" class="btn btn-primary">添加用户</a>
        </div>

        <!-- 用户列表表格 -->
        <table class="table table-bordered table-hover">
            <thead class="table-light">
                <tr>
                    <<th>序号</</th>
                    <<th>用户名</</th>
                    <<th>昵称</</th>
                    <<th>邮箱</</th>
                    <<th>手机号</</th>
                    <<th>状态</</th>
                    <<th>操作</</th>
                </tr>
            </thead>
            <tbody>
                <!-- 遍历用户列表 -->
                <tr th:each="user, status : ${userList}">
                    <td th:text="${status.count}"></td>
                    <td th:text="${user.username}"></td>
                    <td th:text="${user.nickname}"></td>
                    <td th:text="${user.email}"></td>
                    <td th:text="${user.phone}"></td>
                    <td>
                        <span th:if="${user.status == 1}" class="badge bg-success">正常</span>
                        <span th:unless="${user.status == 1}" class="badge bg-danger">禁用</span>
                    </td>
                    <td>
                        <!-- 查看详情 -->
                        <a th:href="@{/user/view/detail(id=${user.id})}" class="btn btn-sm btn-info">详情</a>
                        <!-- 编辑 -->
                        <a href="#" class="btn btn-sm btn-warning">编辑</a>
                        <!-- 删除 -->
                        <a href="#" class="btn btn-sm btn-danger">删除</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    <!-- 引用公共页脚 -->
    <div th:replace="common/layout :: footer"></div>

    <!-- 引入Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

【图 6-2 用户列表页面截图】(标注:Thymeleaf 语法使用、页面布局)

6.3.3 编写用户详情页面(userDetail.html)

html

预览

<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
    <div th:replace="common/layout :: header"></div>

    <div class="container mt-4">
        <h2>用户详情</h2>
        <div class="card" style="max-width: 600px;">
            <div class="card-body">
                <h5 class="card-title" th:text="${user.nickname}"></h5>
                <p class="card-text">
                    <strong>用户名:</strong><span th:text="${user.username}"></span><br>
                    <strong>邮箱:</strong><span th:text="${user.email}"></span><br>
                    <strong>手机号:</strong><span th:text="${user.phone}"></span><br>
                    <strong>状态:</strong>
                    <span th:if="${user.status == 1}" class="badge bg-success">正常</span>
                    <span th:unless="${user.status == 1}" class="badge bg-danger">禁用</span><br>
                    <strong>创建时间:</strong><span th:text="${user.createTime}"></span><br>
                    <strong>更新时间:</strong><span th:text="${user.updateTime}"></span>
                </p>
                <a th:href="@{/user/view/list}" class="btn btn-secondary">返回列表</a>
            </div>
        </div>
    </div>

    <div th:replace="common/layout :: footer"></div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

【图 6-3 用户详情页面截图】(标注:用户信息展示、返回按钮)

6.3.4 页面访问测试

6.4 常见问题排查

七、权限控制和安全控制:Spring Security 实战

Web 应用的权限控制是保障系统安全的核心,Spring Security 是 Spring 生态的安全框架,提供了用户认证、授权、防 CSRF 攻击等功能,本节讲解 SpringBoot 整合 Spring Security,实现基于角色的权限控制。

7.1 核心概念

7.2 SpringBoot 整合 Spring Security

7.2.1 引入依赖

在 pom.xml 中已通过 Spring Initializr 引入 Spring Security 依赖:

xml

<!-- Spring Security -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

【图 7-1 Spring Security 依赖截图】(标注:依赖坐标)

7.2.2 自定义用户详情服务(UserDetailsService)

Spring Security 默认使用内存用户,实际开发中需从数据库查询用户信息,需实现 UserDetailsService 接口:

java

运行

package com.example.springbootwebdemo.config.security;

import com.example.springbootwebdemo.entity.SysUser;
import com.example.springbootwebdemo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 自定义用户详情服务,从数据库查询用户信息
 */
@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 1. 根据用户名查询数据库用户
        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username", username));
        if (sysUser == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }

        // 2. 构建用户权限(此处简化,实际应从数据库查询用户角色/权限)
        String[] authorities = new String[0];
        if ("admin".equals(username)) {
            authorities = new String[]{"ROLE_ADMIN", "user:list", "user:add", "user:delete"}; // 管理员权限
        } else {
            authorities = new String[]{"ROLE_USER", "user:list"}; // 普通用户权限
        }

        // 3. 返回Spring Security的User对象(包含用户名、密码、权限)
        return User.withUsername(sysUser.getUsername())
                .password(sysUser.getPassword()) // 数据库中密码需加密(如BCrypt)
                .authorities(authorities) // 权限列表
                .accountExpired(false) // 账号未过期
                .accountLocked(false) // 账号未锁定
                .credentialsExpired(false) // 凭证未过期
                .enabled(sysUser.getStatus() == 1) // 账号是否启用(与数据库状态一致)
                .build();
    }
}

【图 7-2 自定义 UserDetailsService 截图】(标注:数据库查询、权限构建)

7.2.3 配置密码加密方式

Spring Security 要求密码必须加密存储,使用 BCryptPasswordEncoder 加密:

java

运行

package com.example.springbootwebdemo.config.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 密码加密配置
 */
@Configuration
public class PasswordConfig {

    @Bean
    public PasswordEncoder passwordEncoder() {
        // 返回BCrypt密码编码器
        return new BCryptPasswordEncoder();
    }
}

【图 7-3 密码加密配置截图】(标注:BCryptPasswordEncoder 实例化)

7.2.4 Spring Security 核心配置

编写 SecurityConfig 配置类,配置认证、授权规则、登录页面等:

java

运行

package com.example.springbootwebdemo.config.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

/**
 * Spring Security核心配置
 */
@Configuration
@EnableWebSecurity // 启用Web安全
@EnableMethodSecurity // 启用方法级别的权限控制(支持@PreAuthorize等注解)
public class SecurityConfig {

    @Autowired
    private CustomUserDetailsService userDetailsService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    /**
     * 配置安全过滤链(认证、授权规则)
     */
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                // 关闭CSRF保护(开发环境简化,生产环境需开启)
                .csrf

  1. 找到 Maven 安装路径下的 conf/settings.xml 文件,用记事本或 IDEA 打开。
  2. 配置本地仓库:本地仓库用于存储下载的依赖包,默认在 C 盘,建议修改到自定义路径:
  3. xml

    <localRepository>D:\Develop\MavenRepository</localRepository>
    
  4. 配置阿里云镜像(解决依赖下载慢的问题):在<mirrors>标签内添加:

    xml

    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>central</mirrorOf>
        <name>阿里云中央仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
    
  5. 配置 JDK 17 编译环境:在<profiles>标签内添加:

    xml

    <profile>
        <id>jdk-17</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>17</jdk>
        </activation>
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
            <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
        </properties>
    </profile>
    
  6. 打开命令提示符,执行 mvn -v 命令,若输出 Maven 版本、Java 版本及安装路径信息,说明配置成功。【图 2-8 Maven 验证结果截图】(标注:mvn -v 命令输出的版本信息)
  7. 访问 JetBrains 官网(https://www.jetbrains.com/idea/download/),下载 Community 版本(免费)或 Ultimate 版本(付费,学生可申请免费授权)。
  8. 安装时勾选 “创建桌面快捷方式”“关联.java 文件”,选择安装路径(如 D:\Develop\IntelliJ IDEA 2023.2),点击 “Next” 完成安装。【图 2-9 IDEA 安装选项截图】(标注:安装路径、勾选选项)
  9. 启动 IDEA,进入 “File”→“New Projects Setup”→“Structure for New Projects”,在 “Project SDK” 中选择本地安装的 JDK 17,点击 “Apply”。【图 2-10 IDEA JDK 全局配置截图】(标注:Project SDK 选择下拉框)
  10. 进入 “File”→“New Projects Setup”→“Settings for New Projects”,搜索 “Maven”,配置以下内容:
    • Maven home path:选择本地 Maven 安装路径(D:\Develop\apache-maven-3.8.8)
    • User settings file:选择修改后的 settings.xml 文件(D:\Develop\apache-maven-3.8.8\conf\settings.xml)
    • Local repository:自动识别 settings.xml 中配置的本地仓库路径,无需手动修改【图 2-11 IDEA Maven 全局配置截图】(标注:Maven home path、User settings file 配置项)
  11. Lombok:简化实体类代码,通过注解(如 @Data)自动生成 getter、setter、toString 等方法。
  12. MyBatisX:MyBatis-Plus 的配套插件,支持 Mapper 接口与 XML 文件跳转、代码生成。
  13. Thymeleaf 插件:提供 Thymeleaf 模板语法高亮、提示功能。
  14. Spring Boot Helper:简化 SpringBoot 项目配置,支持配置文件提示。【图 2-12 IDEA 插件安装截图】(标注:插件搜索框、安装按钮)
  15. 打开浏览器,访问 Spring Initializr 官网(https://start.spring.io/),页面分为 Project Metadata、Dependencies、Options 三个核心区域。【图 3-1 Spring Initializr 网页版截图】(标注:三个核心配置区域)
  16. Project:选择 Maven(默认)
  17. Language:选择 Java
  18. Spring Boot:选择 3.2.0(稳定版)
  19. Group:项目组织 ID,通常填写公司域名反转(如 com.example)
  20. Artifact:项目名称(如 springboot-web-demo)
  21. Name:项目显示名称(默认与 Artifact 一致)
  22. Description:项目描述(如 SpringBoot Web 应用开发实战)
  23. Package name:包名(默认 Group+Artifact,如 com.example.springbootwebdemo)
  24. Packaging:选择 Jar(SpringBoot 默认打包方式,内置 Tomcat,无需额外部署)
  25. Java:选择 17(与本地 JDK 版本一致)
  26. Spring Web:提供 Web 开发核心功能(如 HTTP 请求处理、Controller 支持)
  27. MySQL Driver:MySQL 数据库驱动,用于连接 MySQL 数据库
  28. MyBatis-Plus Starter:MyBatis-Plus 的 SpringBoot Starter,简化持久层开发
  29. Lombok:简化实体类代码
  30. Spring Cache:数据缓存核心依赖
  31. Redis Starter:Redis 缓存实现
  32. Thymeleaf:视图层模板引擎
  33. Spring Security:权限安全控制【图 3-2 依赖选择截图】(标注:搜索框、已选依赖列表)
  34. 点击页面底部 “Generate” 按钮,下载项目压缩包(springboot-web-demo.zip)。
  35. 将压缩包解压到自定义路径(如 D:\Develop\Projects),避免中文和空格。
  36. 打开 IDEA,点击 “File”→“New”→“Project”,选择 “Spring Initializr”,点击 “Next”。
  37. 配置项目基本信息(与网页版一致),点击 “Next”。
  38. 选择依赖(与网页版一致),点击 “Next”。
  39. 选择项目保存路径,点击 “Finish”,IDEA 自动下载依赖并初始化项目。【图 3-3 IDEA 项目初始化流程截图】(标注:各步骤配置界面)
  40. 找到项目启动类 SpringbootWebDemoApplication.java,该类包含 @SpringBootApplication 注解(SpringBoot 核心注解,整合了 @Configuration、@EnableAutoConfiguration、@ComponentScan)。
  41. 右键点击启动类,选择 “Run 'SpringbootWebDemoApplication'”,启动项目。【图 3-5 项目启动类截图】(标注:@SpringBootApplication 注解、main 方法)
  42. 查看 IDEA 控制台输出,若出现以下日志,说明项目启动成功:

    plaintext

    2024-01-20 15:30:00.000  INFO 12348 --- [           main] c.e.s.SpringbootWebDemoApplication       : Started SpringbootWebDemoApplication in 2.56 seconds (process running for 3.02)
    
  43. 打开浏览器,访问http://localhost:8080(默认端口 8080),若出现 “Whitelabel Error Page” 页面,说明 Web 服务器启动成功(无自定义 Controller 时的默认页面)。【图 3-6 项目启动成功日志截图】(标注:启动成功提示信息)【图 3-7 浏览器访问默认页面截图】(标注:Whitelabel Error Page 页面)
  44. 问题 1:项目启动失败,提示 “Port 8080 was already in use”?解决方案:修改 application.yml 中的 server.port 配置,改为未被占用的端口(如 8081),或关闭占用 8080 端口的进程(通过命令 netstat -ano | findstr "8080" 查找进程 PID,在任务管理器中结束该进程)。
  45. 问题 2:启动时提示 “Failed to configure a DataSource”?解决方案:检查 application-dev.yml 中数据库配置是否正确(URL、用户名、密码),确保 MySQL 服务已启动,且数据库 springboot_web_demo 已创建。
  46. 问题 3:依赖下载失败,IDEA 中依赖包显示红色波浪线?解决方案:检查 Maven 配置是否正确(settings.xml 中的镜像和本地仓库),右键项目→“Maven”→“Reload Project” 重新下载依赖。
  47. 下载 MySQL 8.0.35 安装包(官网:https://dev.mysql.com/downloads/mysql/),按向导安装,设置 root 用户密码(如 root)。
  48. 安装完成后,启动 MySQL 服务(通过服务面板或命令 net start mysql80)。【图 4-1 MySQL 服务启动截图】(标注:服务启动状态)
  49. 使用 Navicat 或 MySQL 命令行工具连接 MySQL,执行以下 SQL 创建数据库和用户表(sys_user):

    sql

    -- 创建数据库
    CREATE DATABASE IF NOT EXISTS springboot_web_demo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
    -- 使用数据库
    USE springboot_web_demo;
    
    -- 创建用户表
    CREATE TABLE IF NOT EXISTS sys_user (
        id BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '用户ID',
        username VARCHAR(50) NOT NULL UNIQUE COMMENT '用户名',
        password VARCHAR(100) NOT NULL COMMENT '密码(加密后)',
        nickname VARCHAR(50) COMMENT '昵称',
        email VARCHAR(100) COMMENT '邮箱',
        phone VARCHAR(20) COMMENT '手机号',
        status TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-正常',
        create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
        update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
    ) COMMENT '系统用户表';
    
    -- 插入测试数据
    INSERT INTO sys_user (username, password, nickname, email, phone)
    VALUES ('admin', '$2a$10$7Z4bF8yG9xH0jK1lM2nO3pQ4rS5tU6vW7xY8zZ9aA0bB1cC2dD3e', '管理员', 'admin@example.com', '13800138000'),
           ('user1', '$2a$10$7Z4bF8yG9xH0jK1lM2nO3pQ4rS5tU6vW7xY8zZ9aA0bB1cC2dD3e', '普通用户1', 'user1@example.com', '13800138001');
    
  50. 启动 SpringBoot 项目,打开 Postman 工具,测试各接口:
  51. 问题 1:调用 getById 方法返回 null,数据库中存在对应 ID 的数据?解决方案:检查实体类的 @TableId 注解是否配置正确(type=IdType.AUTO 对应自增主键),确保数据库表的主键是自增的,且实体类的 id 字段类型与数据库一致(如数据库是 BIGINT,实体类是 Long)。
  52. 问题 2:分页查询返回的总条数为 0,数据条数正常?解决方案:确认分页插件已配置,且 DbType 与数据库类型一致(如 MySQL),检查 application-dev.yml 中是否开启了下划线转驼峰(map-underscore-to-camel-case: true)。
  53. 问题 3:条件构造器 like 查询无效?解决方案:like 方法默认不含百分号,需手动添加(如 like ("nickname", "%" + keyword + "%")),或使用 likeLeft、likeRight 方法(likeLeft ("nickname", keyword) 等价于 nickname LIKE '% keyword')。
  54. 访问 Redis 官网(https://redis.io/download/),下载 Windows 版本(或通过 GitHub 镜像下载:https://github.com/tporadowski/redis/releases),选择 Redis-x64-5.0.14.1.zip。
  55. 解压到自定义路径(如 D:\Develop\Redis),解压后核心文件包括 redis-server.exe(服务端)、redis-cli.exe(客户端)。【图 5-1 Redis 解压目录截图】(标注:核心执行文件)
  56. 打开命令提示符,切换到 Redis 解压目录,执行命令:redis-server.exe redis.windows.conf,启动 Redis 服务(默认端口 6379)。
  57. 启动成功后,命令提示符窗口显示 Redis Logo 及服务信息(如 “Ready to accept connections”)。【图 5-2 Redis 服务启动截图】(标注:服务启动成功提示)
  58. 新打开一个命令提示符,切换到 Redis 解压目录,执行命令:redis-cli.exe,进入 Redis 客户端。
  59. 执行 ping 命令,若返回 PONG,说明 Redis 服务正常运行。【图 5-3 Redis 客户端验证截图】(标注:ping 命令及返回结果)
  60. 启动项目,通过 Postman 发送 GET 请求http://localhost:8080/user/1,首次查询:
    • 控制台打印 “从数据库查询用户,ID:1”,说明从数据库获取数据。
    • 打开 Redis 客户端,执行 keys * 命令,显示缓存 key:cache:user:1(cache: 为配置的 key 前缀,user 为缓存名称,1 为 ID)。
    • 执行 get cache:user:1 命令,可查看序列化后的用户数据(JSON 格式,可读性强)。
  61. 再次发送相同请求,控制台无打印,说明从缓存获取数据,查询效率提升。【图 5-8 缓存效果测试截图】(标注:首次查询控制台输出、Redis 缓存 key 和 value)
  62. 发送 DELETE 请求http://localhost:8080/user/1,删除用户:
    • 控制台打印 “删除数据库用户,ID:1”。
    • 执行 Redis 命令 keys *,cache:user:1 已不存在,说明缓存已删除。
  63. 再次查询 ID 为 1 的用户,控制台打印查询日志,说明缓存已失效,从数据库重新查询(此时数据库中用户已删除,返回 null)。
  64. 合理设置缓存过期时间:根据数据更新频率设置,更新频繁的数据(如用户状态)过期时间可缩短(如 10 分钟),更新频率低的数据(如字典数据)可延长(如 24 小时)。
  65. 避免缓存穿透:缓存穿透是指查询不存在的数据,导致每次请求都访问数据库。解决方案:缓存 null 值(需开启 cache-null-values: true)、使用布隆过滤器过滤不存在的 key。
  66. 避免缓存击穿:缓存击穿是指热点 key 过期时,大量请求同时访问数据库。解决方案:使用互斥锁(如 Redis 的 SETNX 命令)、热点 key 永不过期。
  67. 避免缓存雪崩:缓存雪崩是指大量缓存同时过期,导致数据库压力骤增。解决方案:缓存过期时间添加随机值(如 1 小时 ±5 分钟)、分批次设置缓存过期时间。
  68. 问题 1:缓存数据序列化后乱码?解决方案:确认已配置自定义 Jackson 序列化器,且 RedisCacheManager 使用了该配置,避免使用默认的 JdkSerializationRedisSerializer。
  69. 问题 2:@Cacheable 注解不生效?解决方案:检查启动类是否添加 @EnableCaching 注解、方法是否为 public(缓存注解仅对 public 方法生效)、是否在同一个类中调用缓存方法(Spring Cache 基于 AOP,同类调用无法触发代理)。
  70. 问题 3:Redis 连接失败,提示 “Could not get a resource from the pool”?解决方案:检查 Redis 服务是否启动、application.yml 中 Redis 配置(host、port、password)是否正确、Redis 是否开启了保护模式(可通过 redis.conf 修改 protected-mode no)。
  71. th:text:用于标签体内容替换,转义特殊字符。
  72. th:value:用于表单元素的 value 属性绑定。示例:
  73. ${status.index}:索引(从 0 开始)
  74. ${status.count}:计数(从 1 开始)
  75. ${status.odd}:是否为奇数行
  76. ${status.even}:是否为偶数行示例:
  77. th:if:条件为 true 时显示元素。
  78. th:unless:条件为 false 时显示元素(与 th:if 相反)。示例:
  79. th:href:用于<a>标签的跳转路径,支持 SpringMVC 的 @RequestMapping 路径。
  80. th:action:用于<form>标签的提交路径。示例:
  81. 创建公共模板文件 templates/common/layout.html:
  82. 在其他页面引用公共部分:
  83. 启动项目,访问http://localhost:8080/user/view/list,显示用户列表页面,动态渲染数据库中的用户数据。
  84. 点击 “详情” 按钮,跳转到用户详情页面,展示该用户的完整信息。【图 6-4 页面访问效果截图】(标注:列表页面和详情页面的渲染效果)
  85. 问题 1:页面无法访问,提示 “TemplateInputException: Error resolving template”?解决方案:检查模板文件路径是否正确(需放在 templates 目录下)、返回的模板名称是否与文件名一致(不含后缀)、Thymeleaf 依赖是否引入。
  86. 问题 2:页面数据无法渲染,显示默认值?解决方案:检查 Controller 层是否通过 Model 传递数据、Thymeleaf 表达式是否正确(如 ${userList} 是否与 Model 中的属性名一致)、页面是否引入 thymeleaf 命名空间(xmlns:th="http://www.thymeleaf.org")。
  87. 问题 3:修改模板后页面无变化?解决方案:确认 application-dev.yml 中 thymeleaf.cache 设置为 false,或重启项目(开发环境关闭缓存后,修改模板无需重启)。
  88. 认证(Authentication):验证用户身份(如用户名密码登录)。
  89. 授权(Authorization):验证用户是否有权限访问资源(如普通用户无法访问管理员页面)。
  90. 角色(Role):用户的身份标识(如 ROLE_ADMIN、ROLE_USER)。
  91. 权限(Permission):具体的操作权限(如 user:list、user:add)。
SpringBoot专题学习Part30:SpringBoot整合Spring Security实现Web权限控制【完结】 一、概述 目前流行的安全框架有Shiro和Spring Security Shiro较简单易用 Spring Security较复杂 但功能强大 Spring Security能无缝整合SpringBoot 因此SpringBoot底层使用的是SpringSecurity Spring Security是针对Spring项目的安全框架 其可以实现强大的web安全控制 对于安全控制 仅需引入spri... 阅读详情

相关推荐

SpringBoot项目实战:权限控制到数据操作

本文还有配套的精品资源,点击获取 简介:SpringBoot是Pivotal团队推出的框架,目的是简化基于Spring的应用开发。它通过自动配置和内嵌式Web服务器等特性,提供快速开发独立生产级别应用程序的能力。项目中包含权限控制、登录验证、文件上传及CRUD操作等核心功能,是学习和实践SpringBoot的优秀示例。 1. SpringBoot框架概述与核心理念...

weixin_42576186的博客 2182

SpringBoot安全防护实战:JWT+SpringSecurity权限控制全流程

在当今的Web应用开发中,安全性是至关重要的一环。Spring Boot作为一个广泛使用的Java开发框架,为开发者提供了便捷的开发体验。而Spring Security则是Spring生态系统中用于提供身份验证和授权的强大框架。JSON Web Token(JWT)是一种开放标准(RFC 7519),它定义了一种紧凑且自包含的方式,用于在各方之间安全地传输信息。本文将详细介绍如何在Spring Boot项目中结合JWT和Spring Security实现权限控制的全流程。

梵心白莲的博客 615

第一章、isaacsim 及 isaaclab 安装教程

本专栏所有内容将根据上述资源地址展开,请结合食用~

m0_47719040的博客 4804

从环境搭建到项目部署:SpringBoot完整开发实战指南

本文是SpringBoot开发实战指南,覆盖从环境搭建到项目部署全流程。先介绍其约定优于配置、嵌入式服务器等核心优势,再详细讲解JDK 1.8、Maven 3.6.3、IDEA的配置步骤。核心内容包含项目创建、MyBatis-Plus整合、Redis缓存、Thymeleaf视图开发、Spring Security权限控制等,通过“用户管理系统”演示完整开发流程。所有示例基于SpringBoot 2.7.x稳定版,可复现性强,适合Java开发者系统学习企业级应用开发。

锈铁与酒的博客 782

AGX Orin设计-外围电路设计之一

AGX ORIN是英伟达Jetson系列中算力规格最高端的模组,其高达200TOPS/275TOPS的算力可以为各类场景提供澎湃的算力支持,本篇文章针对AGX ORIN的常规外围电路设计做分析描述。

zhiyuchenkeji的博客 4511

ADS笔记,新旧两组仿真数据进行绘图和列表对比

原理图器件参数的不同,怎么进行对比观看,操作如下。

彭辉荣的博客 3882

SpringBoot应用开发全流程指南:从环境配置到项目实战

【代码】SpringBoot应用开发全流程指南:从环境配置到项目实战。

lf6789_的博客 692

实战!在 AMD RX 9070 XT (16G) 上使用原生 Windows ROCm 7.1 部署 ComfyUI + Z-Image-Turbo

本文详细介绍了如何在Windows系统下为AMD Radeon RX 9070 XT显卡配置Z-Image-Turbo AI绘图环境。主要内容包括:安装VS Build Tools和最新显卡驱动,配置Conda Python 3.12环境,安装ROCm 7.1.1 SDK及PyTorch适配版本,部署ComfyUI可视化界面。重点解决了AMD显卡在AI绘图中的适配问题,通过--use-split-cross-attention参数优化显存使用,最终成功搭建了可在消费级16G显存设备上运行的AI绘图环境

qq_33614778的博客 4791

从零到一:现代 Web 应用开发完整指南

随着前后端分离架构的普及,现代 Web 应用开发已形成 “前端交互层 + 后端服务层 + 数据存储层” 的三段式架构。本文将以 **“用户管理系统”** 为实战案例,采用「Vue3+SpringBoot+MySQL」技术栈,从环境搭建到上线部署,拆解开发全流程,帮助新手快速入门,同时为进阶开发者提供优化思路。本文通过实战案例覆盖了 Web 应用开发的核心流程,从技术选型到部署优化,适合新手快速上手。前端:添加 Vuex/Pinia 状态管理、ECharts 数据可视化。

lbjcjnb的博客 601

光学测量仿真软件:Zygo_(12).Zygo软件的用户界面与操作指南

Zygo软件支持用户自定义工具和插件,以扩展软件的功能和适应特定的仿真需求。编写脚本使用Python或其他支持的脚本语言编写自定义工具的脚本。例如,编写一个脚本来计算光束的衍射效率。# 示例脚本:计算光束的衍射效率 import zygo # 导入Zygo软件的API def calculate_diffraction_efficiency(wavelength , grating_period , angle) : """计算光束的衍射效率:param wavelength: 光源波长(单位:米)

kkchenjj的博客 1683

防护装备穿戴检查:基于YOLOv8与UI界面的深度学习应用

通过结合YOLOv8模型与UI界面,本系统实现了防护装备穿戴检查的自动化。该系统能够快速识别工作人员是否正确佩戴了所需的防护装备,帮助提高安全管理水平。未来,随着技术的发展,防护装备穿戴检查系统将在更多领域得到应用,如工业现场、建筑工地等,实现更加精确和高效的实时监控。

YOLO 381

SpringBoot + MyBatis-Plus 快速开发实战:从环境搭建到权限控制完整指南

在Web应用开发课程中,掌握一套高效、规范的开发流程至关重要。本文将带你从零开始,使用SpringBoot + MyBatis-Plus技术栈,完整实现一个具有权限管理功能的Web应用。本教程适合有一定Java基础的同学,我将详细讲解每个关键步骤并提供完整的代码示例。通过本文的详细讲解,我们完成了:✅ 开发环境配置与优化✅ SpringBoot项目快速搭建✅ MyBatis-Plus深度整合与使用✅ 基于Spring Security的权限控制✅ Redis缓存管理实践✅ 完整的项目开发流程。

2403_89800121的博客 1107

UG\NX二次开发 获取对象的引用集

获取对象的引用集,一个对象可能有多个引用集,下面这个封装函数可以获取对象的所有引用集。

王牌飞行员_里海的博客 501

狂神说SpringBoot18:集成SpringSecurity

狂神说SpringBoot系列连载课程,通俗易懂,基于SpringBoot2.2.5版本,欢迎各位狂粉转发关注学习。未经作者授权,禁止转载SpringSecurity安全简介在 Web ...

狂神说 1万+

MATLAB代码转到FPGA代码

添加完文件之后,需要设置输入的数据类型,设置完之后点击Workflow Advisor。MATLAB文件包含一个功能实现文件和测试文件。对应FPGA中的功能文件和测试文件。然后,将功能文件和测试文件添加到相应位置。然后选择APP中的HDL Coder代码。首先需要编写好MATLAB文件。点击链接,就可以查看你看到的代码。可以自己生成代码的语言类型。

小柚子的博客 3068

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

SpringBoot 安全框架 SpringSecurity 实战教程:从登录认证到权限控制

在现代 Web 应用开发中,安全性是至关重要的一环。Spring Boot 作为一款流行的 Java 开发框架,为开发者提供了便捷的开发体验。而 Spring Security 则是 Spring 生态系统中专门用于提供安全服务的框架,它可以帮助开发者轻松实现用户认证和权限控制等功能。本文将通过实战教程的方式,详细介绍如何在 Spring Boot 项目中使用 Spring Security 实现从登录认证到权限控制的完整流程。

梵心白莲的博客 1214

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

【Web项目开发实战】从环境配置搭建到权限控制,一篇搞定完整开发流程

Component@Autowired@Override// 1. 根据用户名查用户throw new UsernameNotFoundException("用户名不存在:" + username);// 2. 根据用户ID查角色编码// 3. 把角色编码转为Spring Security的权限对象// 4. 返回UserDetails对象(包含用户名、密码、权限)@Autowired。

2402_88947063的博客 765

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

SpringBoot安全框架深度整合:OAuth2+JWT实现权限控制的最佳实践

Spring Boot作为一个广泛使用的Java开发框架,提供了强大的安全框架支持。OAuth2和JWT(JSON Web Token)作为现代身份验证和授权的标准解决方案,它们的结合可以为Spring Boot应用提供高效、灵活且安全的权限控制机制。本文将深入探讨如何在Spring Boot应用中深度整合OAuth2和JWT,实现最佳的权限控制实践。

梵心白莲的博客 1635

SpringBoot安全管理终极指南:SpringSecurity从配置到权限控制

在当今数字化时代,应用程序的安全性至关重要。Spring Boot 作为一款广泛使用的 Java 开发框架,为开发者提供了便捷的开发体验。而 Spring Security 则是 Spring 生态系统中用于解决应用程序安全问题的强大工具。本文将为技术人员详细介绍如何在 Spring Boot 项目中使用 Spring Security 进行安全管理,从基础配置到复杂的权限控制,帮助你构建安全可靠的应用程序。

梵心白莲的博客 1245

SpringBoot - 简单构建web服务

SpringBoot 1. 第一个springboot程序 springboot:https://start.spring.io/ 通过该网站进行项目搭建,下载压缩包,解压后导入IDEA 程序的主入口(该类本身就是spring的一个组件): @SpringBootApplication public class HelloworldApplication { public static void main(String[] args) { SpringApplication.run(Hellowor

Life And Code 3427

SpringBoot 实战:从 0 到 1 搭建企业级后端应用

SpringBoot 作为 Spring 生态的 "脚手架",彻底解决了传统 Spring 配置繁琐、依赖冲突等痛点,凭借自动配置、 starters 依赖、嵌入式服务器、生产级特性四大核心优势,成为微服务架构、企业级应用开发的首选框架。本文将带大家从工程搭建到生产部署,完整掌握 SpringBoot 开发流程,并分享能直接落地的性能优化技巧。代码规范:遵循 RESTful API 设计(GET 查询、POST 新增、PUT 修改、DELETE 删除)

LYQ_minLi的博客 1213

SpringBoot应用开发:从入门到精通

通过本文的介绍,你应该对SpringBoot应用开发有了全面的了解。从环境配置到项目开发流程,每一步都是构建高效、可维护SpringBoot应用的关键。希望本文能为你的SpringBoot学习之旅提供帮助。本文为示例博客,实际编写时应根据具体内容添加代码示例、截图等,以增强文章的可读性和实用性。

sdiee的博客 1442

SpringBoot应用开发全攻略:从环境搭建到项目实战的深度剖析

SpringBoot,作为Java领域的一股强大力量,以其简洁的配置、快速的开发效率以及广泛的社区支持,成为了构建现代企业级应用的热门选择。本文将全面深入地探讨SpringBoot应用开发的关键环节,包括开发环境的配置、项目的快速搭建、持久层框架的整合、数据缓存管理、视图开发、权限控制、消息服务和任务管理,以及完整的项目开发流程。生成项目后,我们只需要关注业务逻辑的实现,而无需花费大量时间在项目结构和配置文件的编写上。通过这些注解,我们可以方便地实现数据的缓存管理,从而提升应用的性能。注解来启用缓存功能。

idhsjsj的博客 430

SpringBoot娱乐管理系统实战:从环境搭建到上线部署全流程解析

SpringBoot作为当前主流的Java开发框架,以其自动配置和快速启动特性,大幅降低了企业级应用的门槛。在业务系统开发中,权限控制、数据持久化与高效部署始终是核心挑战。基于JWT的无状态认证方案与MyBatis-Plus的灵活数据访问,为中小型管理系统提供了轻量级解决方案。这类系统广泛应用于娱乐场所、门店运营等场景,涵盖登录认证、权限管理、订单处理及数据统计等完整业务链路。本文以一套实战项目为例,系统梳理从环境初始化、数据库设计到部署上线的全过程,并针对版本兼容、事务处理、配置安全等常见问题给出可操作的

weixin_31236101的博客 317

SpringBoot安全模块实战:整合SpringSecurity与JWT实现权限控制

在当今的Web应用开发中,安全性是至关重要的。Spring Boot作为一个流行的Java开发框架,为开发者提供了便捷的开发体验。而Spring Security是Spring家族中用于提供身份验证和授权的强大框架,JSON Web Token(JWT)则是一种用于在网络应用中安全传输信息的开放标准。本文将详细介绍如何在Spring Boot项目中整合Spring Security与JWT,实现高效的权限控制。

梵心白莲的博客 952

【全流程实战】从 0 到 1 构建 SpringBoot Web 应用:环境→持久层→视图→权限

本文提供了一套完整的Java开发环境配置与SpringBoot项目开发流程。首先介绍了5分钟快速搭建JDK+Maven+IDEA开发环境的方法,包括版本选择和配置技巧。然后详细说明了1分钟创建SpringBoot项目、MyBatis-Plus整合实现零手写CRUD操作、Thymeleaf视图动态渲染以及SpringSecurity实现RBAC权限控制的步骤。整个流程从环境搭建到功能实现都采用极简配置,通过代码生成器和框架内置功能大幅提升开发效率,特别适合快速构建企业级Java Web应用。

FFLLLLL的博客 1131
上一篇: 如何进行数据缓存管理
下一篇: element ui的使用
wan7u
博客等级 码龄2年 5粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值