Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of passing object parameters by Postman

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is the method of transferring object parameters by Postman". In daily operation, I believe that many people have doubts about the method of transferring object parameters by Postman. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of transferring object parameters by Postman?" Next, please follow the editor to study!

Project scenario:

Postman usually needs to pass a variety of parameters, so it is a headache to write parameters, and I don't know how to pass parameters.

Solution:

Consider writing the parameter object to the style of a json string, and then converting the string into a json object

Entity class:

Import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import org.apache.ibatis.annotations.Param;import org.hibernate.validator.constraints.Length;import org.springframework.validation.annotation.Validated;import javax.persistence.Column;import javax.persistence.Id;import javax.persistence.Table;import javax.persistence.Transient;import javax.validation.Valid;import javax.validation.constraints.Digits;import javax.validation.constraints.NotNull;import java.io.Serializable;import java.math.BigDecimal;import java.util.Date;import java.util.List @ Data@AllArgsConstructor@NoArgsConstructor@Table (name = "ssm_funds_main") public class FunsCjyModel implements Serializable {private static final long serialVersionUID = 1L; / * main table id * / @ Id / / @ NotNull (message = "id cannot be empty") @ Length (max = 32 id = "master table id length cannot exceed 32 bits") @ Column (name = "BI_RS_ID") private String biRsId / * training course * / @ NotNull (message = "the training course cannot be empty") @ Length (max = 32 message = "the length of the training course cannot exceed 32 bits") @ Column (name = "TERM_NAME") private String termName / * * invoice buyer * / @ NotNull (message = "invoice buyer cannot be empty") @ Length (max = 32 mag message = "invoice buyer length cannot exceed 32 digits") @ Column (name = "BUYER") private String buyer / * * invoice seller * / @ NotNull (message = "invoice seller cannot be empty") @ Length (max = 32 maxim message = "invoice seller length cannot exceed 32 digits") @ Column (name = "SALLER") private String saller / * * invoice number * / @ Length (max = 32 minicyte message = "invoice number length cannot exceed 32 digits") private String billNo; / * * invoice date * / private Date billDate / * * par amount * / @ Digits (integer = 8 memes = 2 Magi message = "the upper limit of the par value is 8 digits and the upper limit of decimal point is 2 digits") private BigDecimal billSum; / * copy path * / @ Length (max = 100 Magi message = "copy path length cannot exceed 100 digits") private String picPath / * File extension name * / @ Length (max = 10 id message = "the length of the file extension name cannot exceed 100 digits") private String picFileExt; / * * founder * / @ Length (max = 32 id message = "creator id length cannot exceed 32 bits") private String createId; / * * creation time * / private Date createDate / * modifier * / @ Length (max = 32 Transient message = "modifier id length cannot exceed 32 bits") private String modifyId; / * * modify time * / private Date modifyDate; / * * from table collection * / @ Transient @ Valid private List list;}

Parameter style:

{"biRsId": "," termName ":" training "," buyer ":" students "," saller ":" School "," billNo ":" 20210722 "," billSum ":" 900.00 "," createId ":" CJY "," list ": [{" rsId ":" itemName ":" language "," itemSpec ":" Private " "itemUnit": "Yuan", "qty": "10.00", "price": "30.00", "subSum": "300.00", "taxPercent": "300.00", "taxAtm": "30.0"}, {"rsId": "," itemName ":" Mathematics " "itemSpec": "collective", "itemUnit": "yuan", "qty": "20.00", "price": "30.00", "subSum": "600.00", "taxPercent": "600.00", "taxAtm": "60.0"}]}

Control layer code:

RequestMapping ("/ insertFunsDetailTwo") @ ResponseBody public ResultMap insertFunsDetailTwo (String dataStr,@RequestParam (value = "file", required = false) MultipartFile file) {JSONObject dataStrMap = JSONObject.parseObject (dataStr); FunsCjyModel funsCjyModel = new FunsCjyModel (); funsCjyModel.setTermName ((String) dataStrMap.get ("termName")); funsCjyModel.setBuyer ((String) dataStrMap.get ("buyer")); funsCjyModel.setSaller ((String) dataStrMap.get ("saller")) FunsCjyModel.setBillNo ((String) dataStrMap.get ("billNo")); funsCjyModel.setBillSum (funsModelCjyServiceImpl.stringBigeDecimal ((String) dataStrMap.get ("billSum"); funsCjyModel.setCreateId ((String) dataStrMap.get ("createId")); String list1 = JSON.toJSONString (dataStrMap.get ("list")); List list = JSONArray.parseArray (list1,DetailCjyModel.class); funsCjyModel.setList (list); return funsModelCjyService.insertFunsAndDetail (funsCjyModel,file) }

In this way, you can use the form-data of postman to transfer the parameters of the file and collection object.

Add: Postman test interface passes object parameters

Url:

Using the post method to request

In the Headers setting:

Where Body writes object information, where the main red line is:

At this point, the study on "what is the method of passing object parameters by Postman" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report