springboot接口接收xml

news/发布时间2024/5/19 5:39:17

对xml文件的操作也可以借助hutoolXmlUtil.

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. 实体类

注意其中XmlElementWrapperXmlElement的位置

点击查看实体类
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;//    @XmlAttributeprivate DeviceStatInfoDto deviceStatInfo;//    @XmlAttributeprivate List<Record> data;@NoArgsConstructor@AllArgsConstructorpublic static class DeviceStatInfoDto implements Serializable {private int onlineCount;private int offlineCount;private int errorCount;@XmlAttributepublic int getOnlineCount() {return onlineCount;}public void setOnlineCount(int onlineCount) {this.onlineCount = onlineCount;}@XmlAttributepublic int getOfflineCount() {return offlineCount;}public void setOfflineCount(int offlineCount) {this.offlineCount = offlineCount;}@XmlAttributepublic int getErrorCount() {return errorCount;}public void setErrorCount(int errorCount) {this.errorCount = errorCount;}}@NoArgsConstructor@AllArgsConstructorpublic static class Record implements Serializable {private String id;private String name;private String status;private String time;@XmlAttributepublic String getId() {return id;}public void setId(String id) {this.id = id;}@XmlAttributepublic String getName() {return name;}public void setName(String name) {this.name = name;}@XmlAttributepublic String getStatus() {return status;}public void setStatus(String status) {this.status = status;}@XmlAttributepublic 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));
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ulsteruni.cn/article/36285100.html

如若内容造成侵权/违法违规/事实不符,请联系编程大学网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

MibBrowser工具测试服务器告警上报

在工具栏【tools】---》【Trap Receiver】选择与服务器直连网卡的IP地址及对应的端口号(确保自己的电脑可以正常和服务器通信)在BMC Trap位置配置自己电脑的IP地址,用于接收上报的告警信息点击【测试】查看已经正常收到服务器测试上报信息了。你也可以尝试拔盘和拔电源看看是…

Windows Server 2016 中文版、英文版下载 (updated Apr 2024)

Windows Server 2016 中文版、英文版下载 (updated Apr 2024)Windows Server 2016 中文版、英文版下载 (updated Apr 2024) Windows Server 2016 Version 1607,2024 年 4 月更新 请访问原文链接:Windows Server 2016 中文版、英文版下载 (updated Apr 2024),查看最新版。原创…

收集:本地运行Llama3

本地运行Llama3新方法#国外有网友火速分享了在本地(Windows、Linux、Mac)一键运行 Llama 3 的新方法~废话不多说,先看效果。【图1】在视频1倍速播放中,他用 OpenWebUI 在自己的 Macbook Pro M1 Max 64G 上成功运行了 Llama 3 。而且还添加了侧边栏展开收起。【图2】以上效果…

TPU-MLIR快速入门

12.1 TPU-MLIR快速入门 12.1.1 TPU-MLIR简介 后文假定用户已经处于docker里面的/workspace目录。 1.编译ONNX模型 以 yolov5s.onnx 为例, 介绍如何编译迁移一个onnx模型至BM1684X TPU平台运行。 该模型来自yolov5的官网: https://github.com/ultralytics/yolov5/releases/downl…

centos7安装python3.12.3(最新)

一.安装环境: Linux系统:centos7,可以正常访问互联网。 python版本:3.12.3,建议网工直接就是安装python3的最新版本,毕竟python2和我们网工更不相关了。 环境最基本的就这些了 二.安装步骤 1.安装python3: 不多说,直接上安装过程~ #只是将python3.12.3的安装包下载到 /…

Deep Hello world!

目录1. #include <stdio.h>2.int 整形数据类型3.main 函数4.printf 函数5.return 函数6.”{}”与“;” “Hellow world!"是初学者的第一份代码,可以说所学万物代码之基础。下面看一下代码是如何实现的:代码虽然简洁,但是包含了许多C语言的知识,我们从上往下看有…