宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

swagger的使用與步驟

管理 管理 編輯 刪除

1、導(dǎo)入maven工程

首先我們創(chuàng)建一個 Spring Boot 項目,并引入 Swagger3 的核心依賴包,如下:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

2、核心配置

接下來我們在啟動類上添加兩個注解,開啟Swagger功能。

//開啟swagger
@EnableSwagger2
@EnableOpenApi
@SpringBootApplication
public class SwaggerApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(SwaggerApplication.class, args);
    }
 
}

3、啟動項目

接下來讓我們可以啟動項目,然后在瀏覽器中輸入如下地址:

http://localhost:8085/swagger-ui/index.html

注意,端口是自己tomcat啟動時的端口,以自己電腦的為準(zhǔn)

4、進(jìn)入界面

e7fb8202305051809275262.png

5、swagger配置類

package com.swagger.config;
 
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("用戶組")
            .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
            .paths(PathSelectors.ant("/swagger/**"))
            .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
            .title("Api接口文檔")
            .description("API描述")
            .version("1.0") .termsOfServiceUrl("https://www.baidu.com") .build(); }
 
 
}

6、Controller接口配置

@Api(tags = "用戶控制")代表對這個controller的描述

4204b202305051809574129.png

@ApiOperation(value = "查詢所有用戶", notes = "查詢所有用戶信息")代表對接口的描述

2b376202305051810094583.png

package com.swagger.controller;
 
import com.baomidou.mybatisplus.extension.api.R;
import com.swagger.domain.User;
import com.swagger.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@Api(tags = "用戶控制")
@RestController
@RequestMapping("/swagger/user")
@CrossOrigin
@Slf4j
public class UserController {
    @Autowired
    private UserServiceImpl userService;
    @GetMapping("/selectAll")
    @ResponseBody
    @ApiOperation(value = "查詢所有用戶", notes = "查詢所有用戶信息")
    public R selectAll(){
        List<User> list = userService.list();
        System.out.println(list);
        return R.ok(list).setCode(200);
    }
    @PostMapping("/save")
    @ApiOperation(value = "新增用戶", notes = "新增用戶信息")
    public R save(@RequestBody User user){
        return R.ok("success").setCode(200);
    }
 
    @PutMapping("/update")
    @ApiOperation(value = "修改用戶", notes = "修改用戶信息")
    public R update(@RequestBody User user){
        return R.ok("success").setCode(200);
    }
 
    @DeleteMapping("/delete")
    @ApiOperation(value = "刪除用戶", notes = "刪除用戶信息")
    public R delete(int id){
        return R.ok("success").setCode(200);
    }
 
}

7、實體類配置

@ApiModel屬性:description:用于描述實體類

@ApiModel(value = "用戶實體",description = "用戶實體")

8308d202305051810329155.png

@ApiModelProperty屬性:notes:描述該實體類屬性的信息

@ApiModelProperty(notes = "用戶Id")

代碼演示

package com.swagger.domain;
 
import com.baomidou.mybatisplus.annotation.*;
 
import java.io.Serializable;
import java.util.Date;
 
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
 
/**
 * 用戶
 * @TableName pd_auth_user
 */
@TableName(value ="pd_auth_user")
@Data
@ApiModel(value = "用戶實體",description = "用戶實體")
public class User implements Serializable {
    /**
     * ID
     */
    @ApiModelProperty(notes = "用戶Id")
    @TableId(value = "id")
    private Long id;
 
    /**
     * 賬號
     */
    @ApiModelProperty(notes = "賬號")
    @TableField(value = "account")
    private String account;
 
    /**
     * 姓名
     */
    @ApiModelProperty(notes = "姓名")
    @TableField(value = "name")
    private String name;
 
    /**
     * 組織ID
#c_core_org
     */
    @ApiModelProperty(notes = "組織ID")
    @TableField(value = "org_id")
    private Long org_id;
 
    /**
     * 崗位ID
#c_core_station
     */
    @ApiModelProperty(notes = "崗位ID")
    @TableField(value = "station_id")
    private Long station_id;
 
    /**
     * 郵箱
     */
    @ApiModelProperty(notes = "郵箱")
    @TableField(value = "email")
    private String email;
 
    /**
     * 手機(jī)
     */
    @ApiModelProperty(notes = "手機(jī)")
    @TableField(value = "mobile")
    private String mobile;
 
    /**
     * 性別
#Sex{W:女;M:男;N:未知}
     */
    @ApiModelProperty(notes = "性別   W:女;M:男;N:未知")
    @TableField(value = "sex")
    private String sex;
 
    /**
     * 啟用狀態(tài) 1啟用 0禁用
     */
    @ApiModelProperty(notes = "啟用狀態(tài) 1啟用 0禁用")
    @TableField(value = "status")
    private Boolean status;
 
    /**
     * 頭像
     */
    @ApiModelProperty(notes = "頭像")
    @TableField(value = "avatar")
    private String avatar;
 
    /**
     * 工作描述
比如:  市長、管理員、局長等等   用于登陸展示
     */
    @ApiModelProperty(notes = "工作描述\n" +
        "比如:  市長、管理員、局長等等   用于登陸展示")
    @TableField(value = "work_describe")
    private String work_describe;
 
    /**
     * 最后一次輸錯密碼時間
     */
    @ApiModelProperty(notes = "最后一次輸錯密碼時間")
    @TableField(value = "password_error_last_time")
    private Date password_error_last_time;
 
    /**
     * 密碼錯誤次數(shù)
     */
    @ApiModelProperty(notes = "密碼錯誤次數(shù)")
    @TableField(value = "password_error_num")
    private Integer password_error_num;
 
    /**
     * 密碼過期時間
     */
    @ApiModelProperty(notes = "密碼過期時間")
    @TableField(value = "password_expire_time")
    private Date password_expire_time;
 
    /**
     * 密碼
     */
    @ApiModelProperty(notes = "密碼")
    @TableField(value = "password")
    private String password;
 
    /**
     * 最后登錄時間
     */
    @ApiModelProperty(notes = "最后登錄時間")
    @TableField(value = "last_login_time")
    private Date last_login_time;
 
    /**
     * 創(chuàng)建人id
     */
    @ApiModelProperty(notes = "創(chuàng)建人id")
    @TableField(value = "create_user")
    private Long create_user;
 
    /**
     * 創(chuàng)建時間
     */
    @ApiModelProperty(notes = "創(chuàng)建時間")
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private Date create_time;
 
    /**
     * 更新人id
     */
    @ApiModelProperty(notes = "更新人id")
    @TableField(value = "update_user")
    private Long update_user;
 
    /**
     * 更新時間
     */
    @ApiModelProperty(notes = "更新時間")
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    private Date update_time;
 
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}

swagger顯示

5570d202305051811323410.png

8、注解

781952023050518121325.png


請登錄后查看

CRMEB-慕白寒窗雪 最后編輯于2023-05-05 18:12:30

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
1353
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準(zhǔn)確時需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊

切換手機(jī)號登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服