在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档
具体可以查看本站spring boot系列文章:
spring boot项目使用mybatis-plus代码生成实例
具体例子
在使用之前,我们需要添加swagger中maven相关依赖配置
<!--swagger 接口说明文档框架-->
<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>
swagger:
basePackage: com.lewyon.mybatislewyon #包名
title: 标题 #标题
description: lewyon #描述
version: V1.0 #版本号
以上配置包含了swagger文档展示的包名,标题以及描述,版本号等信息
在springApplication添加swagger注解之后,项目启动时,会注入swagger相关配置和代码,
项目启动成功之后
服务地址/swagger-ui.html就是当前swagger文档地址
package com.lewyon.mybatislewyon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@SpringBootApplication
public class MybatislewyonApplication {
public static void main(String[] args) {
SpringApplication.run(MybatislewyonApplication.class, args);
}
}
Api 常用于描述当前Rest的模块信息
ApiOperation 则是当前方法的信息
package com.lewyon.mybatislewyon.user.controller;
import com.lewyon.mybatislewyon.user.entity.User;
import com.lewyon.mybatislewyon.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author lewyon
* @since 2022-06-25
*/
@RestController
@RequestMapping("/user")
@Api(value = "用户", tags = {"用户操作"})
public class UserController {
@Autowired
UserService userService;
@GetMapping("/list")
@ApiOperation("用户列表")
public List<user> listUser() {
return userService.list();
}
@GetMapping("/getUser/{userId}")
@ApiOperation("用户详情")
public User getUserById(@PathVariable long userId) {
return userService.getById(userId);
}
@GetMapping("/updateUser/{user}")
@ApiOperation("更新用户")
public boolean updateUserById(User user) {
return userService.updateById(user);
}
@GetMapping("/addUser/{user}")
@ApiOperation("新增用户")
public boolean addUser(User user) {
return userService.save(user);
}
@GetMapping("/deleteUser/{id}")
@ApiOperation("删除用户")
public boolean delUserById(String id) {
return userService.removeById(id);
}
}
</user>
以上就是spring boot集成swagger生成接口文档的例子,关于swagger更多配置,可以查阅swagger官方文档
文章个人博客地址:
项目源码地址:
项目源码包含了swagger,后续更新关于spring boot集成swagger基础实例
欢迎关注公众号: 程序员布欧,不定期更新技术入门文章
创作不易,转载请注明出处和作者。
Original: https://www.cnblogs.com/akari16/p/16790828.html
Author: 程序员布欧
Title: spring boot使用swagger生成api接口文档
相关阅读
Title: python中pygame模块用法_python中pygame模块用法实例
本文实例讲述了python中pygame模块用法,分享给大家供大家参考。具体方法如下:
import pygame, sys
from pygame.locals import *
set up pygame
pygame.init()
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption(“hello, world”)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
basicFont = pygame.font.SysFont(None, 48)
text = basicFont.render(“Hello ,world”, True, WHITE, BLUE)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery
windowSurface.fill(WHITE)
pygame.draw.polygon(windowSurface, GREEN, ((146, 0),
(291, 106), (236, 277), (56, 277), (0, 106)))
pygame.draw.line(windowSurface, BLUE, (60, 60), (120,
60), 4)
pygame.draw.line(windowSurface, BLUE, (120, 60), (60,
120))
pygame.draw.line(windowSurface, BLUE, (60, 120), (120,
120), 4)
pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)
pygame.draw.ellipse(windowSurface, RED, (300, 250, 40,
80), 1)
pygame.draw.rect(windowSurface, RED, (textRect.left – 20,
textRect.top – 20, textRect.width + 40, textRect.height + 40))
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray
windowSurface.blit(text, textRect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
运行后打出的图片如下:

希望本文所述对大家的Python程序设计有所帮助。
Original: https://blog.csdn.net/weixin_32263417/article/details/113501037
Author: 蒲玉恩
Title: python中pygame模块用法_python中pygame模块用法实例
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/363533/
转载文章受原作者版权保护。转载请注明原作者出处!