在我们开发的过程中会遇到前后端分离的情况,这时候测试就会很麻烦,如果在代码中进行测试,还应当写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怎么测试?
这辈子坚持与不坚持都不可怕,怕的是一直走在独自思考的路上!!!
欢迎加入技术群聊