修改一些bug
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.bamanker.spmybatisplus.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info()
|
||||
.title("Spring Boot 4 DEMO API文档")
|
||||
.version("0.0.1")
|
||||
.description("Spring Boot 4整合示例项目API文档"));
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,15 @@ package com.bamanker.spmybatisplus.controller;
|
||||
|
||||
import com.bamanker.spmybatisplus.entity.User;
|
||||
import com.bamanker.spmybatisplus.entity.dto.UserCreateRequest;
|
||||
import com.bamanker.spmybatisplus.entity.pojo.Result;
|
||||
import com.bamanker.spmybatisplus.entity.dto.Result;
|
||||
import com.bamanker.spmybatisplus.service.UserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.sf.jsqlparser.util.validation.metadata.NamedObject.user;
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @author bamanker
|
||||
@@ -42,7 +40,7 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @return com.bamanker.spmybatisplus.entity.pojo.Result<java.util.List<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @return com.bamanker.spmybatisplus.entity.dto.Result<java.util.List<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @descriptions 获取所有用户列表
|
||||
* @author bamanker
|
||||
* @date 2025/12/11 23:02
|
||||
@@ -53,12 +51,12 @@ public class UserController {
|
||||
if (users != null) {
|
||||
return Result.success(users);
|
||||
}
|
||||
return Result.error(users);
|
||||
return Result.fail(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return org.springframework.http.ResponseEntity<com.bamanker.spmybatisplus.entity.pojo.Result<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @return org.springframework.http.ResponseEntity<com.bamanker.spmybatisplus.entity.dto.Result<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @descriptions 根据id获取用户
|
||||
* @author bamanker
|
||||
* @date 2025/12/11 23:02
|
||||
@@ -87,14 +85,14 @@ public class UserController {
|
||||
//201
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(Result.success(user));
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(Result.error(user));
|
||||
return ResponseEntity.internalServerError().body(Result.fail(user));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param userRequest
|
||||
* @return org.springframework.http.ResponseEntity<com.bamanker.spmybatisplus.entity.pojo.Result<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @return org.springframework.http.ResponseEntity<com.bamanker.spmybatisplus.entity.dto.Result<com.bamanker.spmybatisplus.entity.User>>
|
||||
* @descriptions 更新用户信息
|
||||
* @author bamanker
|
||||
* @date 2025/12/11 23:02
|
||||
@@ -119,7 +117,7 @@ public class UserController {
|
||||
if (isSuccess) {
|
||||
return ResponseEntity.ok(Result.success(user));
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(Result.error(user));
|
||||
return ResponseEntity.internalServerError().body(Result.fail(user));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bamanker.spmybatisplus.entity.pojo;
|
||||
package com.bamanker.spmybatisplus.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -17,12 +17,14 @@ public class Result<T> implements Serializable {
|
||||
private T data;
|
||||
private Integer code;
|
||||
private String message;
|
||||
private Long timestamp;
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
Result<T> result = new Result<>();
|
||||
result.setData(data);
|
||||
result.setCode(1);
|
||||
result.setMessage("success");
|
||||
result.setCode(200);
|
||||
result.setMessage("操作成功");
|
||||
result.setTimestamp(System.currentTimeMillis());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,7 +32,7 @@ public class Result<T> implements Serializable {
|
||||
return success(null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(T data) {
|
||||
public static <T> Result<T> fail(T data) {
|
||||
Result<T> result = new Result<>();
|
||||
result.setData(data);
|
||||
result.setCode(-1);
|
||||
@@ -38,8 +40,16 @@ public class Result<T> implements Serializable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> Result<T> error() {
|
||||
return error(null);
|
||||
public static <T> Result<T> fail(Integer code,String message) {
|
||||
Result<T> result = new Result<>();
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static <T> Result<T> fail() {
|
||||
return fail(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,6 +71,18 @@ springdoc:
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: com.bamanker
|
||||
|
||||
# Knife4j配置
|
||||
knife4j:
|
||||
enable: true # 启用Knife4j增强模式,默认true
|
||||
setting:
|
||||
language: zh_cn # 界面语言,zh_cn表示中文
|
||||
swagger-model-name: 实体类 # 实体类名称显示
|
||||
production: false # 是否开启生产环境保护策略,生产环境建议设置为true
|
||||
basic:
|
||||
enable: false # 是否启用Basic认证,默认false
|
||||
username: admin # Basic认证用户名
|
||||
password: 123456 # Basic认证密码
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
|
||||
Reference in New Issue
Block a user