springboot接口接收xml
对xml文件的操作也可以借助hutool的XmlUtil.
1. xml格式
<root>
<deviceStatInfo onlineCount="64" offlineCount="2" errorCount="0"/>
<data>
<record id="0" name="5号楼10层流量计" status="预警2/正常1/异常3" time="2024-04-10 12:30"/>
<record id="1" name="5号楼13层流量计" status="预警2/正常1/异常3" time="2024-04-10 12:30"/>
<record id="2" name="5号楼16层流量计" status="预警2/正常1/异常3" time="2024-04-10 12:30"/>
<record id="3" name="5号楼19层流量计" status="预警2/正常1/异常3" time="2024-04-10 12:30"/>
</data>
</root>
2. 实体类
注意其中XmlElementWrapper和XmlElement的位置
点击查看实体类
package com.tky.digital.twin.api.dto;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.List;
/**
* @author codor
* @date 2024/04/19 15:31
*/
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = "root")
public class EquipmentWaterPipeStatusMessage implements Serializable {
private static final long serialVersionUID = 1L;
// @XmlAttribute
private DeviceStatInfoDto deviceStatInfo;
// @XmlAttribute
private List<Record> data;
@NoArgsConstructor
@AllArgsConstructor
public static class DeviceStatInfoDto implements Serializable {
private int onlineCount;
private int offlineCount;
private int errorCount;
@XmlAttribute
public int getOnlineCount() {
return onlineCount;
}
public void setOnlineCount(int onlineCount) {
this.onlineCount = onlineCount;
}
@XmlAttribute
public int getOfflineCount() {
return offlineCount;
}
public void setOfflineCount(int offlineCount) {
this.offlineCount = offlineCount;
}
@XmlAttribute
public int getErrorCount() {
return errorCount;
}
public void setErrorCount(int errorCount) {
this.errorCount = errorCount;
}
}
@NoArgsConstructor
@AllArgsConstructor
public static class Record implements Serializable {
private String id;
private String name;
private String status;
private String time;
@XmlAttribute
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlAttribute
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@XmlAttribute
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
@XmlElement(name = "deviceStatInfo")
public DeviceStatInfoDto getDeviceStatInfo() {
return deviceStatInfo;
}
public void setDeviceStatInfo(DeviceStatInfoDto deviceStatInfo) {
this.deviceStatInfo = deviceStatInfo;
}
@XmlElementWrapper(name = "data")
@XmlElement(name = "record")
public List<Record> getData() {
return data;
}
public void setData(List<Record> data) {
this.data = data;
}
}
3. 接口接收
@PostMapping(value = "/waterpipe", produces = {MediaType.APPLICATION_XML_VALUE})
public void waterpipe(@RequestBody EquipmentWaterPipeStatusMessage message) {
System.out.println("JSONUtil.toJsonStr(message) = " + JSONUtil.toJsonStr(message));
}
springboot接口接收xml的更多相关文章
- springboot接口 接收参数为实体对象跟MultipartFile对象报错。
要把文件和普通数据类型分开接口传输,不可以兼容多个类型参数, 建议是传文件一个接口,返回url路径,再和普通数据一起提交,就是两次 企业上的做法都是这样,先用文件服务器保存文件,返回文件路径 http ...
- SpringBoot接口服务处理Whitelabel Error Page(转)
To switch it off you can set server.error.whitelabel.enabled=false http://stackoverflow.com/question ...
- .net webapi 接收 xml 格式数据的三种情况
webapi 接收 xml 的三种方法 前段时间接到一个任务写一个小接口,要接收java端返回过来的短信xml数据. 刚拿到项目,我的第一想法是对方会以什么形式发送xml格式的数据给我呢,设想三种情况 ...
- Springboot接口简单实现生成MySQL插入语句
Springboot接口简单实现调用接口生成MySQL插入语句 在实际测试中,有这样一个需求场景,比如:在性能压力测试中,可能需要我们事先插入数据库中一些相关联的数据. 我们在实际测试中,遇到问题,需 ...
- SpringBoot接口服务处理Whitelabel Error Page
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Erro ...
- SpringBoot接口 - 如何生成接口文档之非侵入方式(通过注释生成)Smart-Doc?
通过Swagger系列可以快速生成API文档,但是这种API文档生成是需要在接口上添加注解等,这表明这是一种侵入式方式: 那么有没有非侵入式方式呢, 比如通过注释生成文档? 本文主要介绍非侵入式的方式 ...
- tcp接收xml数据解析
避免tcp接收xml数据时加上xml数据长度,根据xml数据特点来解析recv到的xml数据 int nPos1 = 0; int nPos2 = 0; int nTempPos = 0; int n ...
- 使用MyBatis的Generator自动创建实体类和dao的接口与xml
在实际的项目中其实建立数据库和设计数据库的时候特别重要,而等数据库设计完成之后,根据数据库创建实体类的工作就特别麻烦和繁琐了,不仅很麻烦,而且很浪费时间,不做又不行,这次就找到了一个简单的方法可以让m ...
- 2、SpringBoot接口Http协议开发实战8节课(1-6)
1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...
- Java文件上传:Restful接口接收上传文件,缓存在本地
接口代码 import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; i ...
随机推荐
- jdk并发包源码解析
一.总括 java底层并发包,笔者将该包大致分成3个层次. 1.基础依赖: 共享变量volatile:有利于线程可见性.Unsafe类:CAS(Compare and Swap)比较并交换,用于并发下 ...
- Mac使用经验汇总
在此记录使用Mac的一些经验技巧. 安装brew 如果按照官网提示安装,巨慢无比,如下: /bin/bash -c "$(curl -fsSL https://raw.githubuserc ...
- MongoDB:文档基本CRUD
- uni-app封装网络请求
在项目下创建一个文件夹https 然后在文件夹下面创建两个文件api.js request.js api.js 用于存放项目的请求接口 request.js 用于存放封装的请求接口get post 在 ...
- DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
前言 最近 DeepSeek 狠狠刷了一波屏,国产大模型真的越来越厉害了,官方的服务器已经爆满了,以至于频繁出现反应迟缓甚至宕机的情况,和两年多之前 ChatGPT 的遭遇颇为相似. 我已经好久没有本 ...
- flutter-TextField文本输入框 限制 数字键盘、输入小数点后两位
关键代码 keyboardType: TextInputType.number, inputFormatters: [ FilteringTextInputFormatter(RegExp(" ...
- 原根学习笔记+BSGS复习笔记
学原根发现拔山盖世算法忘光了,干脆一块儿写了吧. \(BSGS\) 算法 \(BSGS\) 算法,又名拔山盖世算法.北上广深算法.他解决的问题如下: 求解最小的可行的 \(k\),满足 \(a^k\e ...
- 在GitHub上部署个人静态网站
在GitHub上部署个人静态网站 首先将网站设置文件上传到github的一个新建仓库,并公开仓库(会员可不用公开) 找到settings(设置)-page(页面)选项并进入 选择分支(root)并sa ...
- Docker - 部署zyplayer_doc团队协作文档
原文链接:https://mp.weixin.qq.com/s/ew3O0EKLo8KoOMkpT-IePw 一.介绍 zyplayer-doc是一款适合企业和个人使用的WIKI知识库管理工具,提 ...
- Elasticsearch7.8搭建(Windows版本单节点、Linux版本单节点、集群,)
The Elastic Stack, 包括 Elasticsearch.Kibana.Beats 和 Logstash(也称为 ELK Stack).能够安全可靠地获取任何来源.任何格式的数据,然后实 ...