Compare commits

..

2 Commits

Author SHA1 Message Date
孙贺贺 e0455950ad Merge remote-tracking branch 'origin/main'
6 days ago
孙贺贺 a9f2991df1 feat(api): 添加 OpenAPI 文档并优化应用配置
6 days ago

@ -76,6 +76,19 @@
<artifactId>java-jwt</artifactId> <artifactId>java-jwt</artifactId>
<version>4.4.0</version> <version>4.4.0</version>
</dependency> </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> </dependencies>
<build> <build>

@ -1,13 +1,18 @@
package com.trading_platform; 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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "Trading Platform API", version = "1.0"))
@MapperScan("com.trading_platform.mapper")
public class TradingPlatformApplication { public class TradingPlatformApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TradingPlatformApplication.class, args); SpringApplication.run(TradingPlatformApplication.class, args);
} }
} }

@ -33,7 +33,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { 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 * UserService
*/ */
@RestController @RestController
@RequestMapping("/user") @RequestMapping("/users")
@Validated @Validated
/** /**
* UserController * UserController
@ -82,7 +82,7 @@ public class UsersController {
return Result.error("用户名错误"); return Result.error("用户名错误");
} }
// 比较密码,使用MD5加密后的密码与数据库中存储的密码进行比较 // 比较密码,使用SHA256加密后的密码与数据库中存储的密码进行比较
if (Sha256Util.getSHA256String(password).equals(loginUser.getPassword())) { if (Sha256Util.getSHA256String(password).equals(loginUser.getPassword())) {
// 如果密码正确返回成功信息及JWT令牌 // 如果密码正确返回成功信息及JWT令牌
Map<String, Object> claims = new HashMap<>(); 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.Mapper;
import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.Optional; import java.util.Optional;
/** /**
@ -27,8 +28,8 @@ public interface UsersMapper {
* *
* *
* @param user * @param user
* 使MyBatis@InsertSQL * 使MyBatis@InsertSQL
* 使@Optionsuserid * 使@Optionsuserid
*/ */
@Insert("INSERT INTO users (headPicUrl, nickName, username, mobile, password, sex, email, address, status, create_time, update_time) " + @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})") "VALUES (#{headPicUrl}, #{nickName}, #{username}, #{mobile}, #{password}, #{sex}, #{email}, #{address}, #{status}, #{createTime}, #{updateTime})")

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

@ -3,4 +3,14 @@ spring:
name: localhost name: localhost
url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root 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 name: localhost
url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/secondhandtransactions?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root 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