Postman passes object parameters (including collection objects)

Postman usually needs to pass various parameters. This article mainly introduces Postman passing object parameters (including collection objects), which has certain reference value. Interested friends can refer to the project scenario: postman usually needs to pass various
parameters
. Various parameters, in this case, it is a headache to write parameters, and I don’t know how to pass parameters.
Solution:
You can consider writing the parameter object as a json string, and then convert 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;

    /**

     * 主表id

     */

    @Id

   // @NotNull(message = "id不能为空")

    @Length(max = 32,message = "主表id长度不能超过32位")

    @Column(name = "BI_RS_ID")

    private String biRsId;

    /**

     * 所属培训班

     */

    @NotNull(message = "所属培训班不能为空")

    @Length(max = 32,message = "培训班长度不能超过32位")

    @Column(name = "TERM_NAME")

    private String termName;

    /**

     * 发票购买方

     */

    @NotNull(message = "发票购买方不能为空")

    @Length(max = 32,message = "发票购买方长度不能超过32位")

    @Column(name = "BUYER")

    private String buyer;

    /**

     * 发票销售方

     */

    @NotNull(message = "发票销售方不能为空")

    @Length(max = 32,message = "发票销售方长度不能超过32位")

    @Column(name = "SALLER")

    private String saller;

    /**

     * 发票编号

     */

    @Length(max = 32,message = "发票编号长度不能超过32位")

    private String billNo;

    /**

     * 开票日期

     */

    private Date billDate;

    /**

     * 票面金额

     */

    @Digits(integer = 8,fraction = 2,message = "票面金额整数上限为8位,小数点上限为2位")

    private BigDecimal billSum;

    /**

     * 复印件路径

     */

    @Length(max = 100,message = "复印件路径长度不能超过100位")

    private String picPath;

    /**

     * 文件扩展名称

     */

    @Length(max = 10,message = "文件扩展名称长度不能超过100位")

    private String picFileExt;

    /**

     * 创建人

     */

    @Length(max = 32,message = "创建人id长度不能超过32位")

    private String createId;

    /**

     * 创建时间

     */

    private Date createDate;

    /**

     * 修改人

     */

    @Length(max = 32,message = "修改人id长度不能超过32位")

    private String modifyId;

    /**

     * 修改时间

     */

    private Date modifyDate;

    /**

     * 从表集合

     */

    @Transient

    @Valid

    private List<DetailCjyModel> list;

Parameter style:

{

  "biRsId":"",

  "termName":"实训",

  "buyer":"学生",

  "saller":"学校",

  "billNo":"20210722",

  "billSum":"900.00",

  "createId":"CJY",

  "list":[

            {

            "rsId":"",

            "itemName":"语文",

            "itemSpec":"私人",

            "itemUnit":"元",

            "qty":"10.00",

            "price":"30.00",

            "subSum":"300.00",

            "taxPercent":"0.1",

            "taxAtm":"30.0"

            },

{

            "rsId":"",

            "itemName":"数学",

            "itemSpec":"集体",

            "itemUnit":"元",

            "qty":"20.00",

            "price":"30.00",

            "subSum":"600.00",

            "taxPercent":"0.1",

            "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<DetailCjyModel> list = JSONArray.parseArray(list1,DetailCjyModel.class);

        funsCjyModel.setList(list);

        return funsModelCjyService.insertFunsAndDetail(funsCjyModel,file);

In this case, you can use postman's form-data to pass the parameters of files and collection objects

Supplement: Postman test interface passes object parameters

url:

Using the post method request

Set in Headers:

Write the object information in the Body, where the main red line is :

So far, this article about Postman passing object parameters (including collection objects) has been introduced. For more information about Postman passing object parameters, please search for the previous articles of Scenario Home or continue to browse the following related articles. I hope you will learn more in the future Support the editor!

The following is the supporting information. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

Information acquisition method:

Guess you like

Origin blog.csdn.net/2301_76643199/article/details/132188837