赞
踩
项目主体参考我的另一篇:springboot3.2.1整合mybatis-plus-generator3.5.3,并自定义vm模板_mybatis generator 自定义模板-CSDN博客
- <dependency>
- <groupId>org.springdoc</groupId>
- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
- <version>2.0.2</version>
- </dependency>
-
- <dependency>
- <groupId>org.springdoc</groupId>
- <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
- <version>2.0.2</version>
- </dependency>
- package com.zd.controller;
-
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.zd.entity.User;
- import com.zd.resp.ApiResult;
- import com.zd.resp.ResultCode;
- import com.zd.service.UserService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
-
- /**
- * <p>
- * 用户信息表
- * </p>
- *
- * @author zd
- * @since 2024-03-26
- */
- @RestController
- @RequestMapping("/api/v1/user")
- public class UserController {
-
- @Autowired
- private UserService service;
-
- @GetMapping
- public ApiResult<User> list(@RequestParam(required = false) Long current,
- @RequestParam(required = false) Long size) {
- Page<User> page = service.selectPage(current, size);
- return new ApiResult<User>(ResultCode.SUCCESS, page);
- }
-
- @GetMapping("/{id}")
- public ApiResult<User> getByid(@PathVariable("id") Long id) {
- User entity = service.getById(id);
- return new ApiResult<User>(ResultCode.SUCCESS, entity);
- }
-
- @PostMapping
- public ApiResult<User> add(@RequestBody User data) {
- service.save(data);
- return new ApiResult<User>(ResultCode.SUCCESS, data);
- }
-
- @PutMapping("/{id}")
- public ApiResult<User> update(@PathVariable("id") Long id, @RequestBody User data) {
- data.setUserId(id);
- service.updateById(data);
- return new ApiResult<User>(ResultCode.SUCCESS, data);
- }
-
- @DeleteMapping("/{id}")
- public ApiResult<User> delete(@PathVariable("id") Long id) {
- User entity = service.getById(id);
- service.removeById(id);
- return new ApiResult<User>(ResultCode.SUCCESS, entity);
- }
-
-
- }
-
从Springfox迁移过来的,需要修改注解:
- @Api → @Tag
- @ApiIgnore → @Parameter(hidden = true) or @Operation(hidden = true) or @Hidden
- @ApiImplicitParam → @Parameter
- @ApiImplicitParams → @Parameters
- @ApiModel → @Schema
- @ApiModelProperty(hidden = true) → @Schema(accessMode = READ_ONLY)
- @ApiModelProperty → @Schema
- @ApiOperation(value = "foo", notes = "bar") → @Operation(summary = "foo", description = "bar")
- @ApiParam → @Parameter
- @ApiResponse(code = 404, message = "foo") → @ApiResponse(responseCode = "404", description = "foo")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。