1、概念
創(chuàng)新互聯(lián)建站自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元洪江管理區(qū)做網(wǎng)站,已為上家服務(wù),為洪江管理區(qū)各地企業(yè)和個人服務(wù),聯(lián)系電話:18980820575
Swagger2 – 服務(wù)接口文檔,用來前端與后端聯(lián)系,提高之間的溝通,更有效率的完成項目之間的聯(lián)調(diào)。
2、集成
2.1 、通過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到項目里面,可以建static文件夾存放swagger的ui文件
5、通過地址http://localhost:8020/swagger/index.html訪問
網(wǎng)站名稱:springcloud(五):Swagger2的集成
網(wǎng)站路徑:http://www.rwnh.cn/article8/pgchip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、企業(yè)網(wǎng)站制作、響應(yīng)式網(wǎng)站、網(wǎng)站改版、電子商務(wù)、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)