feat(api): 添加 OpenAPI 文档并优化应用配置

- 添加 OpenAPI 依赖并配置 Swagger UI- 更新数据库连接配置
- 修改日志级别配置
- 更新 JWT 密钥
- 优化用户相关 API 路径
- 添加 MyBatis mapper 扫描
main
孙贺贺 3 days ago
parent b0352e4c5f
commit a9f2991df1

8
.idea/.gitignore vendored

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -76,6 +76,19 @@
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<!--openapi 依赖-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
<build>

@ -1,13 +1,18 @@
package com.trading_platform;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "Trading Platform API", version = "1.0"))
@MapperScan("com.trading_platform.mapper")
public class TradingPlatformApplication {
public static void main(String[] args) {
SpringApplication.run(TradingPlatformApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(TradingPlatformApplication.class, args);
}
}

@ -33,7 +33,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 登录和注册路径不进行拦截,以允许未登录用户访问这些路径
registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login", "/user/register");
registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login", "/user/register", "/swagger-ui/**", "/v3/api-docs/**");
}
}

@ -20,7 +20,7 @@ import java.util.Map;
* UserService
*/
@RestController
@RequestMapping("/user")
@RequestMapping("/users")
@Validated
/**
* UserController
@ -82,7 +82,7 @@ public class UsersController {
return Result.error("用户名错误");
}
// 比较密码,使用MD5加密后的密码与数据库中存储的密码进行比较
// 比较密码,使用SHA256加密后的密码与数据库中存储的密码进行比较
if (Sha256Util.getSHA256String(password).equals(loginUser.getPassword())) {
// 如果密码正确返回成功信息及JWT令牌
Map<String, Object> claims = new HashMap<>();

@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.Optional;
/**
@ -27,8 +28,8 @@ public interface UsersMapper {
*
*
* @param user
* 使MyBatis@InsertSQL
* 使@Optionsuserid
* 使MyBatis@InsertSQL
* 使@Optionsuserid
*/
@Insert("INSERT INTO users (headPicUrl, nickName, username, mobile, password, sex, email, address, status, create_time, update_time) " +
"VALUES (#{headPicUrl}, #{nickName}, #{username}, #{mobile}, #{password}, #{sex}, #{email}, #{address}, #{status}, #{createTime}, #{updateTime})")

@ -7,7 +7,7 @@ import java.util.Date;
import java.util.Map;
public class JwtUtil {
private static final String KEY = "itheima";
private static final String KEY = "slqcz";
/**
* JWT

@ -3,4 +3,14 @@ spring:
name: localhost
url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
password: 123456
springdoc:
api-docs:
path: /v3/api-docs
swagger-ui:
path: /swagger-ui.html
logging:
level:
root: debug
com.trading_platform: debug

@ -3,4 +3,14 @@ spring:
name: localhost
url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
password: 123456
springdoc:
api-docs:
path: /v3/api-docs
swagger-ui:
path: /swagger-ui.html
logging:
level:
root: debug
com.trading_platform: debug
Loading…
Cancel
Save