diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -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 diff --git a/trading_platform/pom.xml b/trading_platform/pom.xml index 8a7948d..0401374 100644 --- a/trading_platform/pom.xml +++ b/trading_platform/pom.xml @@ -76,6 +76,19 @@ java-jwt 4.4.0 + + + org.springdoc + springdoc-openapi-starter-webmvc-api + 2.6.0 + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.6.0 + + diff --git a/trading_platform/src/main/java/com/trading_platform/TradingPlatformApplication.java b/trading_platform/src/main/java/com/trading_platform/TradingPlatformApplication.java index 5f00c81..e65b7a3 100644 --- a/trading_platform/src/main/java/com/trading_platform/TradingPlatformApplication.java +++ b/trading_platform/src/main/java/com/trading_platform/TradingPlatformApplication.java @@ -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); + } } diff --git a/trading_platform/src/main/java/com/trading_platform/config/WebConfig.java b/trading_platform/src/main/java/com/trading_platform/config/WebConfig.java index 0b4ed19..fea285c 100644 --- a/trading_platform/src/main/java/com/trading_platform/config/WebConfig.java +++ b/trading_platform/src/main/java/com/trading_platform/config/WebConfig.java @@ -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/**"); } } diff --git a/trading_platform/src/main/java/com/trading_platform/controller/UsersController.java b/trading_platform/src/main/java/com/trading_platform/controller/UsersController.java index 2f26833..b55a4e4 100644 --- a/trading_platform/src/main/java/com/trading_platform/controller/UsersController.java +++ b/trading_platform/src/main/java/com/trading_platform/controller/UsersController.java @@ -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 claims = new HashMap<>(); diff --git a/trading_platform/src/main/java/com/trading_platform/mapper/UsersMapper.java b/trading_platform/src/main/java/com/trading_platform/mapper/UsersMapper.java index 2bb250e..8d76cee 100644 --- a/trading_platform/src/main/java/com/trading_platform/mapper/UsersMapper.java +++ b/trading_platform/src/main/java/com/trading_platform/mapper/UsersMapper.java @@ -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的@Insert注解定义插入操作的SQL语句 - * 使用@Options注解配置插入操作生成的主键返回到user对象的id属性 + * 使用MyBatis的@Insert注解定义插入操作的SQL语句 + * 使用@Options注解配置插入操作生成的主键返回到user对象的id属性 */ @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})") diff --git a/trading_platform/src/main/java/com/trading_platform/utils/JwtUtil.java b/trading_platform/src/main/java/com/trading_platform/utils/JwtUtil.java index 02b2ebd..94b6bd9 100644 --- a/trading_platform/src/main/java/com/trading_platform/utils/JwtUtil.java +++ b/trading_platform/src/main/java/com/trading_platform/utils/JwtUtil.java @@ -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令牌 diff --git a/trading_platform/src/main/resources/application.yml b/trading_platform/src/main/resources/application.yml index b1f565d..ed20da9 100644 --- a/trading_platform/src/main/resources/application.yml +++ b/trading_platform/src/main/resources/application.yml @@ -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 \ No newline at end of file + password: 123456 +springdoc: + api-docs: + path: /v3/api-docs + swagger-ui: + path: /swagger-ui.html + +logging: + level: + root: debug + com.trading_platform: debug \ No newline at end of file diff --git a/trading_platform/target/classes/application.yml b/trading_platform/target/classes/application.yml index b1f565d..ed20da9 100644 --- a/trading_platform/target/classes/application.yml +++ b/trading_platform/target/classes/application.yml @@ -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 \ No newline at end of file + password: 123456 +springdoc: + api-docs: + path: /v3/api-docs + swagger-ui: + path: /swagger-ui.html + +logging: + level: + root: debug + com.trading_platform: debug \ No newline at end of file diff --git a/trading_platform/target/classes/com/trading_platform/TradingPlatformApplication.class b/trading_platform/target/classes/com/trading_platform/TradingPlatformApplication.class index fc601f5..233acbf 100644 Binary files a/trading_platform/target/classes/com/trading_platform/TradingPlatformApplication.class and b/trading_platform/target/classes/com/trading_platform/TradingPlatformApplication.class differ diff --git a/trading_platform/target/classes/com/trading_platform/config/WebConfig.class b/trading_platform/target/classes/com/trading_platform/config/WebConfig.class index 4ff8a85..245140a 100644 Binary files a/trading_platform/target/classes/com/trading_platform/config/WebConfig.class and b/trading_platform/target/classes/com/trading_platform/config/WebConfig.class differ diff --git a/trading_platform/target/classes/com/trading_platform/controller/UsersController.class b/trading_platform/target/classes/com/trading_platform/controller/UsersController.class index 54d2209..fd12b5b 100644 Binary files a/trading_platform/target/classes/com/trading_platform/controller/UsersController.class and b/trading_platform/target/classes/com/trading_platform/controller/UsersController.class differ diff --git a/trading_platform/target/classes/com/trading_platform/utils/JwtUtil.class b/trading_platform/target/classes/com/trading_platform/utils/JwtUtil.class index 74331aa..15c080f 100644 Binary files a/trading_platform/target/classes/com/trading_platform/utils/JwtUtil.class and b/trading_platform/target/classes/com/trading_platform/utils/JwtUtil.class differ