步驟如下:
1、將framework-server版本號由1.5.5升級至1.5.6:
<framework-server.version>1.5.6</framework-server.version>
2、在application.properties添加以下配置:
#是否開啟swagger生產環境需要設置為false
swagger.enable = true
#swagger api-docs版本號
swagger.api.info.version = 1.0.0
#swagger api-docs標題
swagger.api.info.title = framework-example api文檔
#swagger掃描annotation包路徑,該路徑要包含接口和實體類
swagger.resource.package = com.meitong.framework.server.example
3、將接口和實體類以及接口入參添加swagger相關注解,示例如下:
接口:
@Path("/restResource")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Api(value = "Rest resource operations")
public interface RestResource {
<framework-server.version>1.5.6</framework-server.version>
2、在application.properties添加以下配置:
#是否開啟swagger生產環境需要設置為false
swagger.enable = true
#swagger api-docs版本號
swagger.api.info.version = 1.0.0
#swagger api-docs標題
swagger.api.info.title = framework-example api文檔
#swagger掃描annotation包路徑,該路徑要包含接口和實體類
swagger.resource.package = com.meitong.framework.server.example
3、將接口和實體類以及接口入參添加swagger相關注解,示例如下:
接口:
@Path("/restResource")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Api(value = "Rest resource operations")
public interface RestResource {
@GET
@Path("/invokeGet/{id}/{name}")
@ApiOperation(value = "invokeGet示例", notes = "invokeGet說明", response = List.class, httpMethod = "GET")
List<String> invokeGet(@PathParam("id") Integer id, @PathParam("name") String name);
@Path("/invokeGet/{id}/{name}")
@ApiOperation(value = "invokeGet示例", notes = "invokeGet說明", response = List.class, httpMethod = "GET")
List<String> invokeGet(@PathParam("id") Integer id, @PathParam("name") String name);
/**
* invokePost method
*
* @param ids
* @return List<String>
*/
@POST
@Path("/invokePost")
@ApiOperation(value = "invokePost示例", notes = "invokePost說明", response = List.class, httpMethod = "POST")
List<String> invokePost(List<Integer> ids);
* invokePost method
*
* @param ids
* @return List<String>
*/
@POST
@Path("/invokePost")
@ApiOperation(value = "invokePost示例", notes = "invokePost說明", response = List.class, httpMethod = "POST")
List<String> invokePost(List<Integer> ids);
@PUT
@Path("/invokePut")
@ApiOperation(value = "invokePut示例", notes = "invokePut說明", response = Void.class, httpMethod = "PUT")
void invokePut(List<String> names);
@Path("/invokePut")
@ApiOperation(value = "invokePut示例", notes = "invokePut說明", response = Void.class, httpMethod = "PUT")
void invokePut(List<String> names);
@DELETE
@Path("/invokeDelete/{id}")
@ApiOperation(value = "invokeDelete示例", notes = "invokeDelete說明", response = Void.class, httpMethod = "DELETE")
void invokeDelete(@PathParam("id") Integer id);
@Path("/invokeDelete/{id}")
@ApiOperation(value = "invokeDelete示例", notes = "invokeDelete說明", response = Void.class, httpMethod = "DELETE")
void invokeDelete(@PathParam("id") Integer id);
@GET
@Path("/getAllUser")
@ApiOperation(value = "獲取所有的用戶",notes = "使用說明",response = User.class,responseContainer = "List",httpMethod = "GET")
List<User> getAllUser();
@POST
@Path("/insert")
@ApiOperation(value = "新增用戶",notes = "使用說明",response = Void.class,httpMethod = "POST")
void insert(@ApiParam(value = "用戶信息",name = "user",required = true) User user);
}
實體類:
@ApiModel(description = "用戶信息")
public class User {
@Path("/insert")
@ApiOperation(value = "新增用戶",notes = "使用說明",response = Void.class,httpMethod = "POST")
void insert(@ApiParam(value = "用戶信息",name = "user",required = true) User user);
}
實體類:
@ApiModel(description = "用戶信息")
public class User {
@ApiModelProperty(value = "用戶名",required = true)
private String userName;
@ApiModelProperty(value = "用戶ID",required = true)
private String userId;
private String userName;
@ApiModelProperty(value = "用戶ID",required = true)
private String userId;
//get and set
}
4.接口文檔訪問:
http://ip:port/swagger.json
5.完成系統接入以后,將步驟4生成的接口文檔地址匯總發到我這邊。我需要將這些接口集成到swagger-ui中
6.swagger-ui訪問地址
http://101.37.117.177:8080/static/#/
}
4.接口文檔訪問:
http://ip:port/swagger.json
5.完成系統接入以后,將步驟4生成的接口文檔地址匯總發到我這邊。我需要將這些接口集成到swagger-ui中
6.swagger-ui訪問地址
http://101.37.117.177:8080/static/#/
如果集成到swagger-ui中會存在跨域請求問題,所以需要添加一個全局的過濾器:
com.meitong.framework.server.filters.CORSFilter
