Cyan Blog Cyan Blog
首页
  • Java (opens new window)
  • JUC (opens new window)
  • JVM (opens new window)
  • Redis

    • Redis安装 (opens new window)
    • Redis基础 (opens new window)
    • Redis实战 (opens new window)
    • Redis集群安装 (opens new window)
    • Redis分布式缓存 (opens new window)
    • Redis多级缓存 (opens new window)
    • Redis原理 (opens new window)
  • 管理工具

    • Maven (opens new window)
    • Git (opens new window)
  • SSM

    • Spring (opens new window)
    • SpringBoot (opens new window)
    • Mybatis (opens new window)
    • MybatisPlus (opens new window)
  • 微服务

    • Docker (opens new window)
    • RabbitMQ (opens new window)
    • SpringCloud (opens new window)
    • Dubbo (opens new window)
    • MongoDB (opens new window)
    • Zookeeper (opens new window)
  • Java面试题 (opens new window)
  • JUC面试题 (opens new window)
  • JVM面试题 (opens new window)
  • Linux面试题 (opens new window)
  • SQL面试题 (opens new window)
  • Maven面试题 (opens new window)
  • Redis面试题 (opens new window)
  • SSM面试题 (opens new window)
  • SpringCloud面试题 (opens new window)
  • Linux (opens new window)
  • C++ (opens new window)
  • 数据库

    • MySQL (opens new window)
    • NoSQL (opens new window)
  • 软件测试

    • 软件测试 (opens new window)
  • 加密解密 (opens new window)
  • bilibili字幕提取 (opens new window)
  • 道理 (opens new window)
  • 关于博主

    • Github (opens new window)
    • CSDN (opens new window)
  • 关于本站

    • 如何搭建博客网站 (opens new window)
首页
  • Java (opens new window)
  • JUC (opens new window)
  • JVM (opens new window)
  • Redis

    • Redis安装 (opens new window)
    • Redis基础 (opens new window)
    • Redis实战 (opens new window)
    • Redis集群安装 (opens new window)
    • Redis分布式缓存 (opens new window)
    • Redis多级缓存 (opens new window)
    • Redis原理 (opens new window)
  • 管理工具

    • Maven (opens new window)
    • Git (opens new window)
  • SSM

    • Spring (opens new window)
    • SpringBoot (opens new window)
    • Mybatis (opens new window)
    • MybatisPlus (opens new window)
  • 微服务

    • Docker (opens new window)
    • RabbitMQ (opens new window)
    • SpringCloud (opens new window)
    • Dubbo (opens new window)
    • MongoDB (opens new window)
    • Zookeeper (opens new window)
  • Java面试题 (opens new window)
  • JUC面试题 (opens new window)
  • JVM面试题 (opens new window)
  • Linux面试题 (opens new window)
  • SQL面试题 (opens new window)
  • Maven面试题 (opens new window)
  • Redis面试题 (opens new window)
  • SSM面试题 (opens new window)
  • SpringCloud面试题 (opens new window)
  • Linux (opens new window)
  • C++ (opens new window)
  • 数据库

    • MySQL (opens new window)
    • NoSQL (opens new window)
  • 软件测试

    • 软件测试 (opens new window)
  • 加密解密 (opens new window)
  • bilibili字幕提取 (opens new window)
  • 道理 (opens new window)
  • 关于博主

    • Github (opens new window)
    • CSDN (opens new window)
  • 关于本站

    • 如何搭建博客网站 (opens new window)
  • MicroServices

  • SpringBoot

    • big-event
    • 苍穹外卖

    • Spring注解
    • 数据库设计文档
  • SSM

  • Spring生态
  • SpringBoot
2025-03-16
0
0

Spring注解

# Spring注解

# @RunWith(SpringRunner.class)

# 前后端数据传输注解

@RequestParam、@PathVariable、 @RequestBody、@RequestHeader

没有指定注解则是通过查询字符串传递

注解 作用 示例场景
@RequestParam 从 URL 查询参数中提取数据,有多个同名参数自动转为集合 /users?id=123
@PathVariable 从 URL 路径参数中提取数据 /users/123
@RequestBody 从 HTTP 请求体中提取数据 JSON 或 XML 格式的请求体
@RequestHeader 从 HTTP 请求头中提取数据 Authorization: Bearer <token>

@PathVariable 常用于 RESTful 风格的 URL 中获取资源标识符,如 ID、名称等。@RequestBody 常用于处理 POST、PUT 等请求方法,接收请求体中的数据。

方式 安全性分析 适用场景 优缺点
URL 查询参数/查询字符串(Query String) 不安全,数据暴露在 URL 中,容易被日志、浏览器历史记录或第三方工具捕获。 适合传递非敏感数据(如分页参数、搜索关键字)。 不适用于传递大量或敏感数据
URL 路径参数 较不安全,数据仍然暴露在 URL 中,但比查询参数稍隐蔽。 适合传递资源标识符(如 /users/123)。 简洁明了,易于理解。不适合传递大量或复杂的数据。
HTTP 头部 较安全,数据不暴露在 URL 中,但需确保使用 HTTPS 加密传输。 适合传递敏感信息(如身份验证令牌、API 密钥)。
请求体(POST/PUT/PATCH) 较安全,数据不暴露在 URL 中,但仍需使用 HTTPS 加密传输。 适合传递敏感信息或大量数据(如登录信息、支付数据)。 多种格式,如JSON、XML、form-data。传输大量或复杂的数据。不能用于GET请求
特性 GET POST PUT PATCH
语义 获取资源 创建资源或触发操作 更新或替换资源 部分更新资源
幂等性 幂等 不是幂等的 幂等的 不是幂等的
数据传递 URL 查询参数 请求体 请求体 请求体
是否修改资源 否 是 是 是
使用场景 获取数据 创建资源、触发操作 更新或替换资源 部分更新资源

# RestController

  • RESTful风格
  • 所有方法的返回值都会直接写入 HTTP 响应体,而不是解析为视图。
  • 默认情况下,返回值会被转换为 JSON 格式

# @Transaction事务

上次更新: 2025/4/8 11:18:04
项目优化
数据库设计文档

← 项目优化 数据库设计文档→

最近更新
01
项目优化
05-06
02
项目优化
05-06
03
延迟消息
05-05
更多文章>
Theme by Vdoing | Copyright © 2025-2025 Cyan Blog
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式