spring-boot - 我如何在 Springdoc-swagger-ui 中获取 RequestBody null 或 empty 中的属性?
问题描述
我想包含属性为空或空的 RequestBody。
我目前在 Swagger-UI 中得到的内容如下所示
{
"name": "string",
"imagen": "string"
}
而我想要的是下面的
{
"name": "null", or "name": ""
"imagen": "null" or "imagen": ""
}
我在 Maven POM 中使用它
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-common -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-common</artifactId>
<version>1.5.11</version>
</dependency>
我的控制器是这样实例化的
@RestControllerAdvice
@RequestMapping("gender")
@CrossOrigin("*")
public class GenderController {
private GenderService genderService;
@Autowired
public GenderController(GenderService genderService) {
this.genderService = genderService;
}
@PostMapping("create")
@Operation(description = "Create a gender in the DB")
public ResponseEntity<?> createGender(
GenderCompressDto dto) throws Exception {
try {
GenderCompressDto genderDto = dto;
} catch (InvalidFileNameException e) {
throw new InvalidFileNameException(e.getMessage(),
"Field empty or null");
}
return new ResponseEntity<>(dto, HttpStatus.OK);
}
}
我的 GenderCompressDto
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GenderCompressDto {
private String name = null;
private String imagen = null;
}
解决方案
推荐阅读
- python - 在 Python 中定义用于调用 CPLEX 的目录
- keras - 如何在 keras 中保存经过训练的神经网络的偏差?
- apache-kafka - 如何使用 Kafka Streams 统计在特定时间段内生成事件的用户?
- python - Django 中的用户类型模型
- c - 在c中将文件输入读入结构数组的简单方法?
- laravel - 使用 laravel tinker 和 Carbon 批量更新数据
- css - 理解 :not 选择器 css
- python - 在 Python 中,如何在为属性赋值的类中创建方法
- python - Pandas 元数据属性未传递给 Groupby 对象的组
- json - 有没有办法使用 curl 在环回中发送非常复杂的查询?