标签:sele cal selectors builder pid 更改 body err int
@Api(value="用户controller",tags={"用户操作接口"})
@RestController
public class UserController {
}
@Api(value="UserController",tags={"用户接口"})
@RestController
public class UserController {
@ApiOperation(value="获取用户信息",tags={"获取用户信息"},notes="注意")
@GetMapping("/getUserInfo")
public User getUserInfo(@ApiParam(name="id",value="用户id",required=true) Long id,@ApiParam(name="username",value="用户名") String username) {
User user = userService.getUserInfo();
return user;
}
}
@ApiModel(value="user",description="用户对象")
@Data
public class User implements Serializable{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value="用户名",name="username",example="xingguo")
private String username;
@ApiModelProperty(value="状态",name="state",required=true)
private Integer state;
private String password;
private String nickName;
private Integer isDeleted;
@ApiModelProperty(value="ids",hidden=true)
private String[] ids;
private List<String> idList;
}
@ApiOperation("修改用户信息")
@PostMapping("/updateUserInfo")
public int updateUserInfo(@RequestBody @ApiParam(name="用户对象",value="json格式",required=true) User user){
int num = userService.updateUserInfo(user);
return num;
}
@ApiOperation("查询测试")
@GetMapping("select")
//@ApiImplicitParam(name="name",value="用户名",dataType="String", paramType = "query")
@ApiImplicitParams({
@ApiImplicitParam(name="name",value="用户名",dataType="string", paramType = "query",example="xingguo"),
@ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query")})
public void select(){
}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- 下面这个界面更好看,更好用-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.5</version>
</dependency>
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* swagger-api 配置
*
* @author wzm
* @version 1.0.0
* @date 2019/6/15
**/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2 {
/**
* http://localhost:8085/fabric-net/swagger-ui.html
* http://localhost:8085/fabric-net/doc.html
*/
private static final String SWAGGER_SCAN_BUSINESS_PACKAGE = "com.thyc.fabric.controller.business";
private static final String BUSINESS_VERSION = "1.0.0";
private static final String SWAGGER_SCAN_FABRIC_PACKAGE = "com.thyc.fabric.controller.fabric";
private static final String FABRIC_VERSION = "1.0.0";
@Bean
public Docket createBusinessApi() {
List<Parameter> pars = new ArrayList<>();
ParameterBuilder ticketPar1 = new ParameterBuilder();
ticketPar1.name("Authorization").description("登录令牌")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(ticketPar1.build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(pars)
//分组名不支持中文
.groupName("business")
.apiInfo(apiBusinessInfo())
.pathMapping("/")
.select()
// 对所有api进行监控
.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BUSINESS_PACKAGE))
// 错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// 对根下所有路径进行监控
.paths(PathSelectors.regex("/.*"))
.build();
}
private ApiInfo apiBusinessInfo() {
Contact contact = new Contact("thyc","thyc.com","thyc@email");
return new ApiInfoBuilder()
//设置文档的标题
.title("Business")
//设置文档的描述->1.Overview
.description("业务模块数据管理")
//设置文档的版本信息-> 1.1 Version information
.termsOfServiceUrl("http://localhost:8085/fabric-net")
.contact(contact)
.version(BUSINESS_VERSION)
.build();
}
//------------------------------------------------------------------------------------------------------------------
@Bean
public Docket createFabricApi() {
List<Parameter> pars = new ArrayList<Parameter>();
ParameterBuilder ticketPar1 = new ParameterBuilder();
ticketPar1.name("Authorization").description("登录令牌")
.modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(ticketPar1.build());
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(pars)
//分组名不支持中文
.groupName("fabric")
.apiInfo(apiFabricInfo())
.pathMapping("/")
.select()
// 对所有api进行监控
.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_FABRIC_PACKAGE))
// 错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// 对根下所有路径进行监控
.paths(PathSelectors.regex("/.*"))
.build();
}
private ApiInfo apiFabricInfo() {
Contact contact = new Contact("thyc","thyc.com","thyc@email");
return new ApiInfoBuilder()
//设置文档的标题
.title("Fabric-Network")
//设置文档的描述->1.Overview
.description("超级账本网络信息管理")
//设置文档的版本信息-> 1.1 Version information
.termsOfServiceUrl("http://localhost:8085/fabric-net")
.contact(contact)
.version(FABRIC_VERSION)
.build();
}
}
标签:sele cal selectors builder pid 更改 body err int
原文地址:https://www.cnblogs.com/jockming/p/12233433.html