| 注解 | 使用位置 | 注意事项 |
|---|---|---|
| @Api | 用于controller类上 | 基于类的整体描述 |
| @ApiOperation | 用于controller类内部的方法上 | 基于方法功能的描述 |
| @ApiImplicitParams | 用于controller类内部的方法上 | 非Model对象的参数描述,包含多个@ApiImplicitParam |
| @ApiImplicitParam | 用于@ApiImplicitParams内 | 单个参数的描述 |
| @ApiModel | 用于参数为Model对象(自定义的实体类)的类上 | 多个参数封装在一个实体类内 |
| @ApiModelProperty | 用于@ApiModel对应实体类内属性上 | 与@ApiModel联合使用,用于对类内属性的描述 |
| @ApiResponses | 用于controller类内部的方法上 | 对Response描述,内部包含多个@ApiResponse (类似@ApiImplicitParams) |
| @ApiResponse | 用于@ApiResponses内 | 单个Response code的相关描述 |
@Api(tags = "同步权限",produces = "application/json; charset=UTF-8",protocols = "https")
@RestController
@Slf4j
@Validated
public class PermissionController {
@Value("${timeout}")
private long deferTimeout;
@Resource
PermissionService permissionService;
@ApiOperation("查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "role", value = "角色", dataType = "String"),
@ApiImplicitParam(name = "table", value = "表名", dataType = "String")
})
@RequestMapping(method = {RequestMethod.GET,RequestMethod.POST},value = "/permission/search",produces = "application/json; charset=UTF-8")
public Object search(@RequestParam String role,@RequestParam String table){
return Mono.create(sink->{
try {
sink.success(permissionService.search(role,table));
} catch (Exception e) {
sink.success(WebResult.getServerErrorResult(e.toString()));
log.error(LogUtil.getServerErrorLog("search error,",e));
}
}).timeout(Duration.ofMillis(deferTimeout),Mono.just(WebResult.getServerTimeOutResult()));
}
@ApiOperation("新增")
@PostMapping(value = "/permission/add",produces = "application/json; charset=UTF-8")
public Object add(@RequestBody PermissionEntity entity){
return Mono.create(sink->{
try {
sink.success(permissionService.add(entity));
} catch (Exception e) {
sink.success(WebResult.getServerErrorResult(e.toString()));
log.error(LogUtil.getServerErrorLog("add error,",e));
}
}).timeout(Duration.ofMillis(deferTimeout),Mono.just(WebResult.getServerTimeOutResult()));
}
@ApiOperation("更新")
@PostMapping(value = "/permission/update",produces = "application/json; charset=UTF-8")
public Object update(@RequestBody PermissionEntity entity){
return Mono.create(sink->{
try {
sink.success(permissionService.update(entity));
} catch (Exception e) {
sink.success(WebResult.getServerErrorResult(e.toString()));
log.error(LogUtil.getServerErrorLog("update error,",e));
}
}).timeout(Duration.ofMillis(deferTimeout),Mono.just(WebResult.getServerTimeOutResult()));
}
@ApiOperation("删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "数据唯一id", dataType = "String")
})
@PostMapping(value = "/permission/del",produces = "application/json; charset=UTF-8")
public Object del(@RequestParam String id){
return Mono.create(sink->{
try {
sink.success(permissionService.del(id));
} catch (Exception e) {
sink.success(WebResult.getServerErrorResult(e.toString()));
log.error(LogUtil.getServerErrorLog("update error,",e));
}
}).timeout(Duration.ofMillis(deferTimeout),Mono.just(WebResult.getServerTimeOutResult()));
}
}
@Data
@ApiModel(description = "权限配置信息")
public class PermissionEntity {
@ApiModelProperty(value = "唯一id")
@Null(groups = Crud.Create.class,message = "_id必须为null")
@Field(value = "_id")
private String id;
@ApiModelProperty(value = "角色")
@NotBlank(message = "role不能为空")
private String role;
@ApiModelProperty(value = "权限")
@NotNull(message = "permission不能为空")
private Map permission;
@ApiModelProperty(value = "更新的用户名")
private String updateUser;
@ApiModelProperty(value = "更新时间:yyyy-MM-dd HH:mm:ss",hidden = true)
@Null(message = "updateTime必须为null,由系统自动生成")
private String updateTime;
}
注意:
案例中的代码引用有自己封装的类,如LogUtil,使用时忽略即可,不影响正常功能。
效果:
@Api
@ApiOperation
@ApiModel
@ApiModelProperty
@ApiImplicitParams
@ApiImplicitParam



