postMan simple to use

After separation of the front and rear sections, the interface will need to be tested, as well as various parameters of the request object's encountered various problems, summary of what

  a, list parameter, form is not the form of parameter passing

  b, main test parameters

1, the test entity class

/**
 * @author Levi
 * @date 2019/9/18 9:31
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Animal {
private String name;
private Integer type;
private String num;
private Long id;
private Date birthDate;
List<Animal> animalList;
private Animal animal2;
}

Test Controller

    @PostMapping("/animals")   //简略版本测试
    public AjaxResponse saveArticle(@RequestBody Animal animal) {

        log.info("saveArticle:{}",animal);
        return  AjaxResponse.success(animal);
    }

    @PostMapping("/animals2")
    public AjaxResponse saveArticle2(@ModelAttribute Animal animal) {

        log.info("saveArticle:{}",animal);
        return  AjaxResponse.success(animal);
    }
It means for receiving @RequestBody json string attribute, which can contain objects:

Background can successfully return the results and print: note submitted by the type of raw json

 

 

 

 2, using @ModelAttribute receiving formation in the background, using a form to submit data Postman

 

 

 Another case, both the single parameter, but also the object, modify the second interface:

@PostMapping("/animals2")
public AjaxResponse saveArticle2(@ModelAttribute Animal animal,
@RequestParam (value = "id", required = true) Long id) {

log.info("saveArticle:{}",animal);
return AjaxResponse.success(animal);
}

 

 这样请求,后台只能接收到前面一个id

 

 

 两个id均可获得值

当对象中还有对象,需要用“对象.属性”进行传值

 

 

 

 

 请求参数如上

 

 

 

 

 得到了animal2的值

 
















 

Guess you like

Origin www.cnblogs.com/liweiweicode/p/10942769.html