·參數上添加
@RequestMapping(value = "/add", method = RequestMethod.POST)@ApiOperation(value = "添加用戶", notes = "增加用戶")public Resultadd( @ApiParam(name = "token", value = "token",required = true) @RequestParam(name = "token", required = true) String token, @ApiParam(name = "userName",value = "用戶暱稱",required = true) @RequestParam(name = "userName",required = true) String userName, @ApiParam(name = "mobile",value = "手機",required = true) @RequestParam(name = "mobile",required = true) String mobile) {
·展開bean對象參數
public RetsimpleList(@Validated @ModelAttribute FileSimpleListDTO fileSimpleQueryDTO) {//..}
·忽略bean自定義參數說明顯示
@ApiOperation(value = "更新員工信息", notes = "更新員工信息", response = SwaggerSimpleResultConstant.class)@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主鍵ID", required = true, paramType = "path"), @ApiImplicitParam(name = "name", value = "姓名", required = true, paramType = "query")})@RequestMapping(value = "/{id}", method = { RequestMethod.PUT })public Mapedit(@ApiIgnore Employee employee) {
·直接在bean中添加參數說明
@ApiModel(value = "用戶信息")public class UserVo { @ApiModelProperty(value = "用戶id", required = true) private long userId; @ApiModelProperty(value = "暱稱", required = true) private long userName;
說明:
@ApiModel(value = “用戶信息”) 解釋實體bean
@ApiModelProperty(value = “用戶id”, required = true) 解釋屬性
6、配置完成,訪問API頁面
http://localhost:服務端口/swagger-ui.html
7、整合spring Security實現訪問API頁面輸入用戶名密碼
maven依賴:配置文件添加:security.basic.path=/swagger-ui.htmlsecurity.basic.enabled=truesecurity.user.name=lovnxsecurity.user.password=123456 org.springframework.boot spring-boot-starter-security
閱讀更多 JAVA小酷 的文章