postman测试@requestBody注解 参数为对象且对象中包含属性为集合的形式

在我们开发的过程中会遇到前后端分离的情况,这时候测试就会很麻烦,如果在代码中进行测试,还应当写json格式的字符串,测试完成后,还应该将原来的代码进行删掉。真实麻烦和困难。

今天我为什么要给大家讲解一下使用postman测试 接口为对象且对象中包含属性为list集合的形式
就是因为网上讲解不全面 比较含糊 今天为大家全面细致的讲解一下

下面从controller开始为大家截图

@RequestMapping(value = "/addDeviceWithAttribute", method = RequestMethod.POST,consumes = "application/json;charset=utf-8")
    public SysResult addDeviceWithAttribute(@RequestBody(required = false)  DeviceWithAttribute deviceWithAttribute) {
    	try {
			return zzDeviceService.addDeviceWithAttribute(deviceWithAttribute);
		} catch (Exception e) {
			e.printStackTrace();
			return new SysResult(ErrorUtil.CODE5000, e.getMessage(), null);
		}
    }

下面将实体类发送给大家 注意这类有一个属性deviceAttribute为集合 泛型为AttributeInnerAttributeDevice

public class DeviceWithAttribute implements Serializable {
    private String id;
    private String deviceId;
    private String deviceName;
    private String deviceAlias;
    private String deviceFirm;
    private String deviceModel;
    private String deviceImg;
    private String deviceTypeId;
    private String sortCode;
    private String updateTime;
    private String isDel;
    private List<AttributeInnerAttributeDevice> deviceAttribute;
    }

下面为AttributeInnerAttributeDevice的实体类 注意这里 id时自动生成的 deviceId是上个实体类传过来的 所以我们在进行postman测试传参的时候 只需要传入attributeId和attributeValue即可

public class AttributeInnerAttributeDevice implements Serializable {

    private String id;
    private String attributeId;
    private String deviceId;
    private String attributeValue;
}

下面为大家带来重点 就是postman怎么测试?

在这里插入图片描述
这辈子坚持与不坚持都不可怕,怕的是一直走在独自思考的路上!!!

欢迎加入技术群聊
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值