您好,登錄后才能下訂單哦!
1、概念
Swagger2 – 服務(wù)接口文檔,用來(lái)前端與后端聯(lián)系,提高之間的溝通,更有效率的完成項(xiàng)目之間的聯(lián)調(diào)。
2、集成
2.1 、通過(guò)pom文件導(dǎo)入swagger
<dependency>
<groupId>swagger-springmvc</groupId>
<artifactId>swagger-springmvc</artifactId>
</dependency>
2.2、建立swagger模塊,編寫模塊類
@Configuration
@EnableWebMvc
@EnableSwagger
@ComponentScan(basePackages={"com.sz.xx"})
public class ApiSwaggerConfig extends WebMvcConfigurerAdapter{
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)
{
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
public SwaggerSpringMvcPlugin customImplementation()
{
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(new String[] { "/xx/.*?" })
.apiVersion("0.0.1")
.swaggerGroup("api");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("XX API接口文檔", "API-DOC", "", "test@163.com", "My License", "My Apps API License URL");
return apiInfo;
}
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
{
configurer.enable();
}
class GtPaths extends SwaggerPathProvider {
GtPaths() {
}
protected String applicationPath() {
return "/restapi";
}
protected String getDocumentationPath()
{
return "/restapi";
}
}
}
}
3、代碼里面使用swagger
3.1、UserContoller
@Api(value="userApi", description="user管理接口", position=1)
@Controller
@ApiService
public class UserContoller{
@ApiOperation(notes="新增用戶接口", value="新增用戶(開發(fā)責(zé)任人:xx)")
@ApiServiceOperation("新增用戶接口")
@RequestMapping(value={"/xx/user/add"}, method={RequestMethod.POST})
@ResponseBody
public Response<Integer> createSoftsimBinding(@RequestBody SoftsimBindingCreateReq req)
{
}
4、導(dǎo)入swagger相關(guān)的ui到項(xiàng)目里面,可以建static文件夾存放swagger的ui文件
5、通過(guò)地址http://localhost:8020/swagger/index.html訪問
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。