招摇输入参数所需

required for input parameters on swagger

当我在休息时将 @RequestParamrequired = true 一起使用并且在 swagger 上测试它时,它将与旁边的 *required 标记一起显示.

@GetMapping(path = "/getinfo")
    public ResponseEntity<?> getMyInfo(@RequestParam(value = "input", required = true)  int input, other request parameters)

但是现在,如果我使用 @ModelAttribute 将 url 映射到对象,我该如何在 swagger 上实现相同的效果。

@GetMapping(path = "/getinfo")
        public ResponseEntity<?> getMyInfo(@ModelAttribute MyObject myObject)

您可以尝试使用注解@ApiParam

@GetMapping(path = "/getinfo")
public ResponseEntity<?> getMyInfo(@ModelAttribute("myObject") MyObject myObject)

在您的 MyObject 中 class

public class MyObject {

  private long id;

  @ApiParam(name = "name", value = "Name is Mandatory", required = true)   
  private String name;

}

现在,name 将成为 *必填 字段。