diff --git a/.gitignore b/.gitignore
index b7b6d46..875f9d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,5 +32,5 @@ build/
### VS Code ###
.vscode/
-/src/main/resources/application-dev.properties
+/src/main/resources/application-dev.yml
/logs
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c7560a7..b395525 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
org.springframework.boot
spring-boot-starter-websocket
@@ -67,6 +71,30 @@
org.springframework.boot
spring-boot-starter-validation
+
+
+ com.github.penggle
+ kaptcha
+ 2.3.2
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.22
+
+
+
+ com.google.code.gson
+ gson
+ 2.10.1
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
diff --git a/src/main/java/xyz/playedu/api/PlayeduApiApplication.java b/src/main/java/xyz/playedu/api/PlayeduApiApplication.java
index f1df994..7312ef1 100644
--- a/src/main/java/xyz/playedu/api/PlayeduApiApplication.java
+++ b/src/main/java/xyz/playedu/api/PlayeduApiApplication.java
@@ -2,12 +2,13 @@ package xyz.playedu.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class PlayeduApiApplication {
- public static void main(String[] args) {
- SpringApplication.run(PlayeduApiApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(PlayeduApiApplication.class, args);
+ }
}
diff --git a/src/main/java/xyz/playedu/api/config/KaptchaConfig.java b/src/main/java/xyz/playedu/api/config/KaptchaConfig.java
new file mode 100644
index 0000000..46b46ce
--- /dev/null
+++ b/src/main/java/xyz/playedu/api/config/KaptchaConfig.java
@@ -0,0 +1,42 @@
+package xyz.playedu.api.config;
+
+import com.google.code.kaptcha.impl.DefaultKaptcha;
+import com.google.code.kaptcha.util.Config;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.Properties;
+
+import static com.google.code.kaptcha.Constants.*;
+
+@Configuration
+public class KaptchaConfig {
+
+ @Bean(name = "captchaProducer")
+ public DefaultKaptcha getKaptchaBean() {
+ DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
+ Properties properties = new Properties();
+ // 是否边框
+ properties.setProperty(KAPTCHA_BORDER, "yes");
+ // 字符颜色
+ properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black");
+ // 图片宽度
+ properties.setProperty(KAPTCHA_IMAGE_WIDTH, "120");
+ // 图片高度
+ properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "40");
+ // 字符大小
+ properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38");
+ // 验证键码
+ properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "playedu");
+ // 字符长度
+ properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
+ // 字体样式
+ properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
+ // 图片样式
+ properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
+
+ defaultKaptcha.setConfig(new Config(properties));
+
+ return defaultKaptcha;
+ }
+}
diff --git a/src/main/java/xyz/playedu/api/config/PlayEduConfig.java b/src/main/java/xyz/playedu/api/config/PlayEduConfig.java
new file mode 100644
index 0000000..3f891fb
--- /dev/null
+++ b/src/main/java/xyz/playedu/api/config/PlayEduConfig.java
@@ -0,0 +1,5 @@
+package xyz.playedu.api.config;
+
+public class PlayEduConfig {
+ public static String REDIS_PREFIX = "playedu:";
+}
diff --git a/src/main/java/xyz/playedu/api/config/RedisConfig.java b/src/main/java/xyz/playedu/api/config/RedisConfig.java
new file mode 100644
index 0000000..b4b71d9
--- /dev/null
+++ b/src/main/java/xyz/playedu/api/config/RedisConfig.java
@@ -0,0 +1,28 @@
+package xyz.playedu.api.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+@Configuration
+public class RedisConfig {
+
+ @Bean(name = "redisTemplate")
+ public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
+ RedisTemplate redisTemplate = new RedisTemplate<>();
+ StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+ GenericJackson2JsonRedisSerializer JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
+
+ redisTemplate.setConnectionFactory(redisConnectionFactory);
+ redisTemplate.setValueSerializer(JsonRedisSerializer);
+ redisTemplate.setKeySerializer(stringRedisSerializer);
+ redisTemplate.setHashKeySerializer(stringRedisSerializer);
+ redisTemplate.setHashValueSerializer(JsonRedisSerializer);
+
+ return redisTemplate;
+ }
+
+}
diff --git a/src/main/java/xyz/playedu/api/controller/ExceptionController.java b/src/main/java/xyz/playedu/api/controller/ExceptionController.java
index 549db18..f097eb9 100644
--- a/src/main/java/xyz/playedu/api/controller/ExceptionController.java
+++ b/src/main/java/xyz/playedu/api/controller/ExceptionController.java
@@ -2,6 +2,7 @@ package xyz.playedu.api.controller;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.ObjectError;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -19,17 +20,17 @@ public class ExceptionController {
// }
@ExceptionHandler(ServiceException.class)
- public JsonResponse serviceExceptionHandler(ServiceException e) {
+ public JsonResponse serviceExceptionHandler(ServiceException e) {
return JsonResponse.error(e.getMessage(), 1);
}
@ExceptionHandler(HttpMessageNotReadableException.class)
- public JsonResponse serviceExceptionHandler(HttpMessageNotReadableException e) {
+ public JsonResponse serviceExceptionHandler(HttpMessageNotReadableException e) {
return JsonResponse.error("参数为空", 406);
}
@ExceptionHandler(MethodArgumentNotValidException.class)
- public JsonResponse serviceExceptionHandler(MethodArgumentNotValidException e) {
+ public JsonResponse serviceExceptionHandler(MethodArgumentNotValidException e) {
StringBuffer errorMsg = new StringBuffer();
List allErrors = e.getBindingResult().getAllErrors();
for (ObjectError tmpError : allErrors) {
@@ -39,4 +40,9 @@ public class ExceptionController {
return JsonResponse.error(msg, 406);
}
+ @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
+ public JsonResponse serviceExceptionHandler(HttpRequestMethodNotSupportedException e) {
+ return JsonResponse.error("请求method错误", 400);
+ }
+
}
diff --git a/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java b/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java
index 3708fdf..ee989b0 100644
--- a/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java
+++ b/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java
@@ -5,8 +5,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.playedu.api.domain.AdminUser;
-import xyz.playedu.api.exception.ServiceException;
-import xyz.playedu.api.service.impl.AdminUserServiceImpl;
+import xyz.playedu.api.service.AdminUserService;
import xyz.playedu.api.types.PaginationResult;
import xyz.playedu.api.types.JsonResponse;
@@ -14,10 +13,10 @@ import xyz.playedu.api.types.JsonResponse;
public class AdminUserController {
@Autowired
- private AdminUserServiceImpl adminUserService;
+ private AdminUserService adminUserService;
@GetMapping("/admin/user/index")
- public JsonResponse