1.一个config配置文件 扫描下包,一个注解就完事了
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("v1")
.apiInfo(apiInfo())
//要扫描的包路径
.select().apis(RequestHandlerSelectors.basePackage("com.example.onetwo.controller"))
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.useDefaultResponseMessages(false);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Swagger测试项目").version("1.0").build();
}
}
扫描controller 在controller上加个注解:
@RestController
@RequestMapping("/waw/one")
public class OneController {
@Resource
private OneService oneService;
/**
* 通过id查询单条记录
*/
@ApiOperation(value = "获取用户信息", notes = "根据id查询用户信息")
@PostMapping(value = "/getUserInfoById")
public BaseResponse getUserInfoById(String id){
if(StringUtils.isEmpty(id)){
return ResponseTools.commonResponse(500,"请求参数不能为空!");
}
UserInfoPojo userInfoPojo = oneService.getUserInfoById(id);
return ResponseTools.successResponse(userInfoPojo);
}
}
image.png
网友评论