返回结果封装类如何添加中文说明
@ApiModel(description = "通用响应实体") public class ResponseWrapper<T> { @ApiModelProperty(value = "响应码", example = "200") private Integer code; @ApiModelProperty(value = "数据实体") private T data; @ApiModelProperty(value = "消息提示", example = "操作成功") private String message; // getter和setter省略 }
@ApiModel(description = "用户实体") public class User { @ApiModelProperty(value = "用户ID", example = "1") private Long id; @ApiModelProperty(value = "用户名称", example = "张三") private String name; // getter和setter省略 }
关键点: ResponseWrapper<User>
@ApiOperation(value = "获取用户信息", notes = "根据用户ID获取用户详细信息") @GetMapping("/{userId}") public ResponseWrapper<User> getUser(@PathVariable Long userId) { User user = userService.getUserById(userId); return new ResponseWrapper<>(200, user, "操作成功"); }
使用实体类作为参数时,在传参列表中去掉不需要的字段
public class YourEntity { // 其他字段... @ApiModelProperty(hidden = true) private String sensitiveInformation; // getters and setters... }
返回结果去掉不需要的字段
public class YourEntity { // 其他字段... @JsonIgnore private Integer column; // getters and setters... }