我有一个类,它是我对两个操作(PUT和POST)的请求正文。
我如何定义PUT中必填且在POST中只读的字段?
就我而言,字段为“ createdDate”和“ updatedDate”
我们正在使用Swaggers Java注释
控制器
@PostMapping("")
@ApiOperation(value = "Create new department", httpMethod = "POST")
@Authorization(value = "Basic")
public ResponseEntity<DepartmentDTO> createDepartment(@ApiParam(required = true) @Valid @RequestBody DepartmentDTO departmentDTO)
@PutMapping("/{id}")
@ApiOperation(value = "Update department", httpMethod = "PUT")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Departamento não encontrado")
})
public ResponseEntity update(@PathVariable("id") Integer id, @Valid @RequestBody DepartmentDTO dto)
域类(仅带有javax和swagger注释)
public class DepartmentDTO {
@ApiModelProperty(readOnly = true)
private Integer id;
@NotEmpty @Size(max = 70)
private String name;
private String location;
@NotNull
private Boolean active;
@ApiModelProperty(readOnly = true)
private LocalDateTime createdDate;
@ApiModelProperty(readOnly = true)
private LocalDateTime updatedDate;
@NotNull
private String auditUser;
}