swagger开发接口,实现验证的入参校验Dto类

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	@Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("com.paascloud")).paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("这是标题")
                .description("简单优雅的restful风格")
                .version("1.0")
                .build();
    }
}

pom文件如下

 


        
            com.github.xiaoymin
            swagger-bootstrap-ui
            1.8.9
        

            org.hibernate
            hibernate-validator
        
        
            org.springframework.boot
            spring-boot-starter-web
        
@Data
@ApiModel(value =  "流程配置")
public class ProcessConfigListVo {

 

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@ApiModelProperty(name = "updateTime" , value = "修改时间")
private Date updateTime;
@ApiParam(name = "required", value = "是否必填", required = true, allowableValues = "0,1")
@NotNull(message = "值为0和1")
@Range(min = 0, max = 1, message = "值为0和1")
private Integer required;
@ApiParam(name = "name", value = "模板名称", required = true)
    @NotBlank(message = "模板名称不能为空")
    private String name;
 @ApiModelProperty(value = "类型 0 备案  1 延期 2结案 ",allowableValues = "0,1,2",required = true)
    @NotNull(message = "范围为0至2")
    @Range(min=0,max=2,message = "范围为0至2")
    private Integer type;

 

constroller类调用的接口进行验证:

 

@PostMapping("/addRecordTemplate")
@ApiOperation("*********")
public Wrapper addTemplat(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file,@Validated AddRecordTemplateDto dto) {
    cmsConstructionTemplateService.addTemplate(token, file, dto);
    return WrapMapper.ok();
}
 

POJO

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ProcessonNodeTimeoutPojo {
@ApiModelProperty(name = "id" , value = "id")
	private String id;

 

 

 

你可能感兴趣的:(SpringBoot,Java,java)