对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; // @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的更多相关文章

  1. springboot接口 接收参数为实体对象跟MultipartFile对象报错。

    要把文件和普通数据类型分开接口传输,不可以兼容多个类型参数, 建议是传文件一个接口,返回url路径,再和普通数据一起提交,就是两次 企业上的做法都是这样,先用文件服务器保存文件,返回文件路径 http ...

  2. SpringBoot接口服务处理Whitelabel Error Page(转)

    To switch it off you can set server.error.whitelabel.enabled=false http://stackoverflow.com/question ...

  3. .net webapi 接收 xml 格式数据的三种情况

    webapi 接收 xml 的三种方法 前段时间接到一个任务写一个小接口,要接收java端返回过来的短信xml数据. 刚拿到项目,我的第一想法是对方会以什么形式发送xml格式的数据给我呢,设想三种情况 ...

  4. Springboot接口简单实现生成MySQL插入语句

    Springboot接口简单实现调用接口生成MySQL插入语句 在实际测试中,有这样一个需求场景,比如:在性能压力测试中,可能需要我们事先插入数据库中一些相关联的数据. 我们在实际测试中,遇到问题,需 ...

  5. SpringBoot接口服务处理Whitelabel Error Page

    转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Erro ...

  6. SpringBoot接口 - 如何生成接口文档之非侵入方式(通过注释生成)Smart-Doc?

    通过Swagger系列可以快速生成API文档,但是这种API文档生成是需要在接口上添加注解等,这表明这是一种侵入式方式: 那么有没有非侵入式方式呢, 比如通过注释生成文档? 本文主要介绍非侵入式的方式 ...

  7. tcp接收xml数据解析

    避免tcp接收xml数据时加上xml数据长度,根据xml数据特点来解析recv到的xml数据 int nPos1 = 0; int nPos2 = 0; int nTempPos = 0; int n ...

  8. 使用MyBatis的Generator自动创建实体类和dao的接口与xml

    在实际的项目中其实建立数据库和设计数据库的时候特别重要,而等数据库设计完成之后,根据数据库创建实体类的工作就特别麻烦和繁琐了,不仅很麻烦,而且很浪费时间,不做又不行,这次就找到了一个简单的方法可以让m ...

  9. 2、SpringBoot接口Http协议开发实战8节课(1-6)

    1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...

  10. Java文件上传:Restful接口接收上传文件,缓存在本地

    接口代码 import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; i ...

随机推荐

  1. mysl 修改数据存储位置后服务启动后停止

    在 Windows 系统中安装完 mysql 后,如果是生产用的机器,通常会修改数据存储位置.基本步骤: 1. 停止 mysql 服务: 2. 修改 my.ini 文件中的 datadir=" ...

  2. 金泰克S300固态硬盘 SM2256K开卡量产

    开卡原因:固态硬盘出现开机正常,用一会就找不到硬盘了,电脑冷启动后又可以识别硬盘,决定根据网上教程进行开卡量产修复试试. 硬盘型号:tigo S300 120GB,主控芯片SM2256K AB,闪存颗 ...

  3. uni-app根据不同的类型绑定不同类名

    <template> <view class="page-demo"> <view class="demo" v-for=&quo ...

  4. uni-app发布体验版本后授权登录很卡

    今天uni-app发布了一个体验版本, 但是我发现扫码登录后: 非常的卡顿在授权登录的时候: 但是在我的模拟器开发的时候, 是非常的流畅的. 没有一点儿的卡顿: 在真机上预览的时候也是非常的流畅的: ...

  5. uni-app封装input组件用于登录

    组件 <template> <view> <view class="uni-form-item uni-column"> <input c ...

  6. V-Control 开箱即用的.NET MAUI组件库发布了!

    之前写过挺多的MAUI Sample,其中有很多代码可以打包成组件,当组件完善到一定程度,我会把控件封装起来放到控件库中. 今天,在这个仓库建立一年零八个月后,我觉得可以考虑将其作为开源库发布. 有很 ...

  7. Irwin-Hall 分布/CF1477F 题解

    Irwin-Hall 分布 对于 \(n\) 个均匀分布于 \([0,1]\) 的连续随机变量 \(X_1,X_2,\dots,X_n\),其和的随机变量 \(X\) 满足: \[P(X\le x)= ...

  8. EMR集群信息查看-Hive

    一.日志 1.hivemetastore日志 简介:查看运行情况,其它组件会通过hivemetastore获取表信息 tail -f /data/emr/hive/logs/hadoop-hiveme ...

  9. Amis坑

    一.特殊字符 1.输入框.多行输入框输入$s字符默认替换成空. 如调用后端接口的输入框输入123$BB123,实际请求的参数为123,$后面的参数消息 解决办法:如确实需要输入$的话,在$前面加\即可 ...

  10. Vue 页面批量导入其他组件

    <template> <div> <template v-for="(item) in names"> <component :is=&q ...