1.2.1 restful api设计示例

本文详细介绍了RESTful API请求参数与Spring MVC后台处理参数的多种方式,包括@RequestParam、@RequestBody、@PathVariable等注解的使用场景,以及如何通过@RequestMapping和@ResponseBody实现不同类型的HTTP请求处理。

Rest API请求参数与Spring后台常用接收参数注解的各种类型介绍。

  • @RequestParam
  • @RequestBody
  • @PathVariable
  • 实体Bean
  • 数据类型

另外还有两个常用方法注解:

  • @RequestMapping
  • @Responsebody

@RequestMapping(“url”),这里的 url写的是请求路径的一部分,一般作用在 Controller的方法上,作为请求的映射地址。

@ResponseBody是作用在方法上的,@ResponseBody 表示该方法的返回结果直接写入 HTTP response body 中,一般在异步获取数据时使用【也就是AJAX】,在使用 @RequestMapping后,返回值通常解析为跳转路径,但是加上 @ResponseBody 后返回结果不会被解析为跳转路径,而是直接写入 HTTP response body 中。 比如异步获取 json 数据,加上 @ResponseBody 后,会直接返回 json 数据。@RequestBody 将 HTTP 请求正文插入方法中,使用适合的 HttpMessageConverter 将请求体写入某个对象。

标准restful api请求资源实例

以student实体为例:

/**
* Get请求
* @return
*/
@RequestMapping(value="student",method=RequestMethod.GET)
@ResponseBody
public Student read(Student student) {
    return student;
}

/**
* POST请求
* @return
*/
@RequestMapping(value="student",method=RequestMethod.POST)
@ResponseBody
public int creat(Student student) {
    return 0;
}

/**
* PUT请求
* @return
*/
@RequestMapping(value="student",method=RequestMethod.PUT)
@ResponseBody
public Student update(Student student) {
    return student;
}

/**
* DELETE请求
* @return
*/
@RequestMapping(value="student",method=RequestMethod.DELETE)
@ResponseBody
public int delete(Student student) {
    return 0;
}
先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱动电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
Below is a list of versions that are available for the restAPI plugin. To find other plugins, please review this listing of most recent releases of all plugins. Plugins extend and enhance the functionality of Openfire. To install plugins, copy the .jar file into the plugins directory of your Openfire installation. Releases Info File Version Released Openfire Version Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.12.0 2025年7月4日 5.0.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.11.0 2024年6月25日 4.8.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.10.2 2023年1120日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.10.1 202211月9日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.10.0 2022年9月29日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.9.1 2022年8月4日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.9.0 2022年8月4日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.8.3 2022年7月19日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.8.2 2022年6月27日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.8.1 2022年6月23日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.8.0 2022年4月6日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.7.1 2022214日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.7.0 2022119日 4.7.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.6.0 2021年6月18日 4.6.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.4.0 2020年224日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.10 2020年1月7日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.9 2019年3月21日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.8 2018年1128日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.7 2018年8月30日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.6 2018年8月27日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.5 2018年8月13日 4.1.1 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.1 2018年4月20日 4.1.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.3.0 2018年3月7日 4.1.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.2.5 2016年10月14日 4.1.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.2.4 2016年7月4日 4.0.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.2.3 2016年5月3日 4.0.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.2.2 2016年120日 4.0.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.2.1 2015年1124日 3.11.0 alpha + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.1.7 2015年1113日 3.10.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.1.6 2015年9月24日 3.9.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.1.5 2015年9月1日 3.9.0 + Plugin REST API Allows administration over a RESTful API. ReadMe Changelog Download 1.0.2 2015年3月3日 3.9.0 + The plugins below, so-called SNAPSHOTS, are build automatically by the continuous integration system. They represent the latest development, but are untested. Snapshots Info File Version Built at Openfire Version Plugin REST API ReadMe Changelog Download 1.12.1-SNAPSHOT 2025年7月4日 5.0.0 + Plugin REST API ReadMe Changelog Download 1.12.0-SNAPSHOT 2025年7月4日 5.0.0 + Plugin REST API ReadMe Changelog Download 1.11.1-SNAPSHOT 2025年7月4日 5.0.0 + Plugin REST API ReadMe Changelog Download 1.11.1-SNAPSHOT 2024年1118日 4.8.0 + Plugin REST API ReadMe Changelog Download 1.11.1-SNAPSHOT 2024年10月5日 4.8.0 + Plugin REST API ReadMe Changelog Download 1.11.1-SNAPSHOT 2024年6月26日 4.8.0 + Plugin REST API ReadMe Changelog Download 1.11.1-SNAPSHOT 2024年6月25日 4.8.0 + Plugin REST API ReadMe Changelog Download 1.11.0-SNAPSHOT 2024年6月25日 4.8.0 + Plugin REST API ReadMe Changelog Download 1.10.3-SNAPSHOT 2024年4月17日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.3-SNAPSHOT 2024年112日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.3-SNAPSHOT 2023年1120日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 2023年6月19日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 2023年5月3日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 2023年126日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 2023年123日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 202212月31日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 20221224日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 20221224日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.2-SNAPSHOT 202211月9日 4.7.0 + Plugin REST API ReadMe Changelog Download 1.10.1-SNAPSHOT 2022111日 4.7.0 +
10-03
根据你提供的 **Openfire REST API 插件版本列表**,我们可以更准确地选择与你的 Openfire 服务器(当前版本:**4.9.2**)兼容的正确插件版本。 --- ### ✅ 推荐安装版本:`restapi-1.11.0` 或 `1.12.0` 从表格中可以看到: | 插件版本 | 支持的最低 Openfire 版本 | 发布时间 | 推荐 | |--------|----------------------|---------|-------| | **1.12.0** | **5.0.0+** ❌ | 2025年7月4日 | 不推荐(需要 Openfire ≥5.0.0) | | **1.11.0** | **4.8.0+** ✅ | 2024年6月25日 | ✅ 推荐!兼容 4.9.2 | | 1.10.2 及以下 | 4.7.0+ | 更早 | 可用但非最新 | > ⚠️ 注意:虽然 `1.12.0` 是最新版,但它要求 **Openfire 5.0.0 或更高版本**,而你使用的是 **4.9.2**,因此 **不兼容**。 --- ### ✅ 正确安装步骤(适配 Openfire 4.9.2) #### 步骤 1:下载推荐版本 `restapi-1.11.0.jar` ```bash cd /tmp wget https://www.igniterealtime.org/projects/openfire/plugins/restapi/download.jsp?version=1.11.0 -O restapi-1.11.0.jar ``` > 如果上述链接重定向失败,可尝试直接从官方镜像下载: > > ```bash > wget https://download.igniterealtime.org/openfire/plugins/restapi/restapi-1.11.0.jar > ``` --- #### 步骤 2:复制到 Openfire 插件目录 ```bash sudo cp /tmp/restapi-1.11.0.jar /opt/openfire/plugins/ ``` Openfire 会自动检测插件并解压加载(通常在几秒内完成)。无需手动解压。 --- #### 步骤 3:等待自动加载或重启服务 你可以查看日志确认是否成功加载: ```bash tail -f /opt/openfire/logs/all.log ``` 搜索关键词: ``` INFO: Loaded plugin 'REST API' ``` 或者重启 Openfire 以强制加载: ```bash sudo systemctl restart openfire ``` --- #### 步骤 4:登录管理控制台启用 REST API 访问: ``` http://localhost:9090 ``` 进入: > **Plugins → REST API Plugin** 点击进入配置页面: 1. ✅ Enable REST API 2. 设置一个强 Shared Secret,例如: ``` your-secret-key-generated-with-openssl ``` (可用命令生成:`openssl rand -base64 32`) 3. 可选:允许远程 IP 访问、开启 CORS 等。 4. 保存设置。 --- #### 步骤 5:测试 API 是否正常工作 ##### 示例:获取所有用户 ```bash curl -X GET "http://localhost:9090/plugins/restapi/v1/users" \ -H "Authorization: Bearer your-secret-key-generated-with-openssl" ``` ✅ 成功响应示例(JSON): ```json { "users": [] } ``` --- ### 🔐 安全建议 | 项目 | 建议 | |------|------| | Shared Secret | 使用至少 32 字符的随机字符串 | | 外网访问 | 禁止外网直接访问 9090 端口 | | HTTPS | 在生产环境中必须启用 SSL/TLS(可在 Openfire 控制台配置) | | 防火墙 | 限制 `/plugins/restapi` 路径仅允许可信 IP 调用 | --- ### 📚 REST API 主要功能端点(v1) | 功能 | 方法 | URL | |------|------|-----| | 获取用户列表 | GET | `/users` | | 创建用户 | POST | `/users` | | 删除用户 | DELETE | `/users/{username}` | | 发送消息 | POST | `/messages` | | 创建群聊房间 | POST | `/chatrooms` | | 获取在线会话 | GET | `/sessions` | 完整文档见: 👉 [https://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html](https://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html) --- ### ❌ 常见错误及解决方法 | 错误 | 原因 | 解决方案 | |------|------|-----------| | `404 Not Found` | 插件未正确加载 | 检查 `/opt/openfire/plugins/restapi/` 是否存在解压后的文件夹 | | `401 Unauthorized` | 密钥错误 | 核对 Authorization 头中的密钥 | | `403 Forbidden` | IP 被拦截 | 检查插件配置中的白名单设置 | | `Plugin not showing up` | 版本不兼容 | 确保使用 `1.11.0` 而不是 `1.12.0` | --- ### ✅ 总结 你现在应该使用 **`restapi-1.11.0.jar`** 来为 Openfire 4.9.2 安装 REST API 插件。这是最后一个支持 4.x 系列的稳定版本之一,功能完整且经过充分测试。 不要使用 `1.12.0`,因为它需要 Openfire 5.0+。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值