├── LICENSE
├── README.md
├── md-assets
├── admin.png
├── app.png
├── er.png
└── teacher.png
├── pom.xml
├── schema.sql
└── src
├── main
├── java
│ └── xyz
│ │ └── refrain
│ │ └── onlineedu
│ │ ├── OnlineEduApplication.java
│ │ ├── annotation
│ │ ├── AccessLimit.java
│ │ ├── ActionRecord.java
│ │ └── TimeCost.java
│ │ ├── aspect
│ │ ├── ActionRecordAspect.java
│ │ └── TimeCostAspect.java
│ │ ├── config
│ │ ├── AliyunConfig.java
│ │ ├── HibernateValidationConfig.java
│ │ ├── LocalDateTimeSerializerConfig.java
│ │ ├── MyBatisPlusConfig.java
│ │ ├── RedisConfig.java
│ │ ├── SwaggerConfig.java
│ │ ├── WebMvcConfig.java
│ │ └── properties
│ │ │ ├── AliyunOssProperties.java
│ │ │ ├── AliyunProperties.java
│ │ │ └── AliyunVodProperties.java
│ │ ├── constant
│ │ ├── CacheKeyPrefix.java
│ │ ├── RS.java
│ │ ├── SessionConstant.java
│ │ └── StatConstant.java
│ │ ├── controller
│ │ ├── admin
│ │ │ ├── AclRoleController.java
│ │ │ ├── AclUserController.java
│ │ │ ├── EduChapterController.java
│ │ │ ├── EduCourseController.java
│ │ │ ├── EduSubjectController.java
│ │ │ ├── EduTeacherController.java
│ │ │ ├── EduVideoController.java
│ │ │ ├── HmBannerController.java
│ │ │ ├── StatController.java
│ │ │ ├── TOrderController.java
│ │ │ └── UctrMemberController.java
│ │ ├── app
│ │ │ ├── ContentController.java
│ │ │ └── UctrMemberController.java
│ │ └── teacher
│ │ │ ├── EduChapterController.java
│ │ │ ├── EduChapterTmpController.java
│ │ │ ├── EduCommentController.java
│ │ │ ├── EduCourseController.java
│ │ │ ├── EduSubjectController.java
│ │ │ ├── EduTeacherController.java
│ │ │ ├── EduVideoController.java
│ │ │ ├── EduVideoTmpController.java
│ │ │ ├── StatController.java
│ │ │ └── SysMessageController.java
│ │ ├── exception
│ │ ├── MyException.java
│ │ └── ServiceException.java
│ │ ├── handler
│ │ ├── MyBatisMetaObjectHandler.java
│ │ └── RestUnifiedExceptionHandler.java
│ │ ├── interceptor
│ │ ├── AbstractSecurityInterceptor.java
│ │ ├── AccessLimitInterceptor.java
│ │ ├── AdminSecurityInterceptor.java
│ │ ├── AppSecurityInterceptor.java
│ │ ├── StatInterceptor.java
│ │ └── TeacherSecurityInterceptor.java
│ │ ├── mapper
│ │ ├── AclRoleMapper.java
│ │ ├── AclUserMapper.java
│ │ ├── EduChapterMapper.java
│ │ ├── EduChapterTmpMapper.java
│ │ ├── EduCommentMapper.java
│ │ ├── EduCourseMapper.java
│ │ ├── EduSubjectMapper.java
│ │ ├── EduTeacherMapper.java
│ │ ├── EduVideoMapper.java
│ │ ├── EduVideoTmpMapper.java
│ │ ├── HmBannerMapper.java
│ │ ├── RelCourseMemberMapper.java
│ │ ├── StatDailyMapper.java
│ │ ├── SysMessageMapper.java
│ │ ├── TOrderMapper.java
│ │ ├── UctrMemberMapper.java
│ │ └── xml
│ │ │ ├── AclRoleMapper.xml
│ │ │ ├── AclUserMapper.xml
│ │ │ ├── EduChapterMapper.xml
│ │ │ ├── EduChapterTmpMapper.xml
│ │ │ ├── EduCommentMapper.xml
│ │ │ ├── EduCourseMapper.xml
│ │ │ ├── EduSubjectMapper.xml
│ │ │ ├── EduTeacherMapper.xml
│ │ │ ├── EduVideoMapper.xml
│ │ │ ├── EduVideoTmpMapper.xml
│ │ │ ├── HmBannerMapper.xml
│ │ │ ├── RelCourseMemberMapper.xml
│ │ │ ├── StatDailyMapper.xml
│ │ │ ├── SysMessageMapper.xml
│ │ │ ├── TOrderMapper.xml
│ │ │ └── UctrMemberMapper.xml
│ │ ├── model
│ │ ├── base
│ │ │ ├── BeanConvert.java
│ │ │ └── ValidGroupType.java
│ │ ├── entity
│ │ │ ├── AclRoleEntity.java
│ │ │ ├── AclUserEntity.java
│ │ │ ├── EduChapterEntity.java
│ │ │ ├── EduChapterTmpEntity.java
│ │ │ ├── EduCommentEntity.java
│ │ │ ├── EduCourseEntity.java
│ │ │ ├── EduSubjectEntity.java
│ │ │ ├── EduTeacherEntity.java
│ │ │ ├── EduVideoEntity.java
│ │ │ ├── EduVideoTmpEntity.java
│ │ │ ├── HmBannerEntity.java
│ │ │ ├── RelCourseMemberEntity.java
│ │ │ ├── StatDailyEntity.java
│ │ │ ├── SysMessageEntity.java
│ │ │ ├── TOrderEntity.java
│ │ │ └── UctrMemberEntity.java
│ │ ├── enums
│ │ │ ├── CourseStatusEnum.java
│ │ │ ├── MessageRoleEnum.java
│ │ │ ├── PayTypeEnum.java
│ │ │ ├── RoleEnum.java
│ │ │ ├── SexEnum.java
│ │ │ └── TeacherStatusEnum.java
│ │ ├── params
│ │ │ ├── AclUserSearchParam.java
│ │ │ ├── BasePageParam.java
│ │ │ ├── EduCommentSearchParam.java
│ │ │ ├── EduCourseSearchParam.java
│ │ │ ├── EduSubjectSearchParam.java
│ │ │ ├── EduTeacherSearchParam.java
│ │ │ ├── HmBannerSearchParam.java
│ │ │ ├── ListParam.java
│ │ │ ├── LoginParam.java
│ │ │ ├── OrderBy.java
│ │ │ ├── RegisterParam.java
│ │ │ ├── TOrderSearchParam.java
│ │ │ ├── UctrMemberSearchParam.java
│ │ │ ├── UpdatePasswordParam.java
│ │ │ └── UpdatePasswordWithAdminParam.java
│ │ ├── securtiy
│ │ │ ├── AclUserDetail.java
│ │ │ ├── EduTeacherDetail.java
│ │ │ └── UctrMemberDetail.java
│ │ └── vo
│ │ │ ├── PageResult.java
│ │ │ ├── R.java
│ │ │ ├── admin
│ │ │ ├── AclRoleVO.java
│ │ │ ├── AclUserVO.java
│ │ │ ├── EduCourseDetailVO.java
│ │ │ ├── EduCourseSimpleVO.java
│ │ │ ├── EduSubjectDetailVO.java
│ │ │ ├── EduSubjectSimpleChildrenVO.java
│ │ │ ├── EduSubjectSimpleParentVO.java
│ │ │ ├── EduTeacherDetailVO.java
│ │ │ ├── EduTeacherSimpleVO.java
│ │ │ ├── HmBannerVO.java
│ │ │ ├── StatCommonVO.java
│ │ │ ├── StatDailyVO.java
│ │ │ └── TOrderVO.java
│ │ │ ├── app
│ │ │ ├── MemberOrderVO.java
│ │ │ ├── UctrMemberDetailVO.java
│ │ │ └── UctrMemberSimpleVO.java
│ │ │ ├── common
│ │ │ └── SysMessageVO.java
│ │ │ └── teacher
│ │ │ ├── EduChapterTmpVO.java
│ │ │ ├── EduChapterVO.java
│ │ │ ├── EduCommentVO.java
│ │ │ ├── EduVideoTmpVO.java
│ │ │ ├── EduVideoVO.java
│ │ │ └── StatTchVO.java
│ │ ├── schedule
│ │ └── StatTask.java
│ │ ├── service
│ │ ├── AclRoleService.java
│ │ ├── AclUserService.java
│ │ ├── AliyunOssService.java
│ │ ├── AliyunVodService.java
│ │ ├── CommonService.java
│ │ ├── EduChapterService.java
│ │ ├── EduChapterTmpService.java
│ │ ├── EduCommentService.java
│ │ ├── EduCourseService.java
│ │ ├── EduCourseTmpService.java
│ │ ├── EduSubjectService.java
│ │ ├── EduTeacherService.java
│ │ ├── EduVideoService.java
│ │ ├── EduVideoTmpService.java
│ │ ├── HmBannerService.java
│ │ ├── StatService.java
│ │ ├── SysMessageService.java
│ │ ├── TOrderService.java
│ │ └── UctrMemberService.java
│ │ └── utils
│ │ ├── CodeAutoGenerator.java
│ │ ├── IPUtils.java
│ │ ├── JsonUtils.java
│ │ ├── LambdaTypeUtils.java
│ │ ├── RUtils.java
│ │ ├── RWriterUtils.java
│ │ ├── RedisUtils.java
│ │ ├── SessionUtils.java
│ │ └── VideoUtil.java
└── resources
│ ├── application-dev.yaml
│ ├── application.yaml
│ └── static
│ └── .gitkeep
└── test
└── java
└── xyz
└── refrain
└── .gitkeep
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Myles
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/md-assets/admin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/snwjas/OnlineEdu/6c62da3669d3e8e2090dcbbd08f7d1b4112177e7/md-assets/admin.png
--------------------------------------------------------------------------------
/md-assets/app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/snwjas/OnlineEdu/6c62da3669d3e8e2090dcbbd08f7d1b4112177e7/md-assets/app.png
--------------------------------------------------------------------------------
/md-assets/er.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/snwjas/OnlineEdu/6c62da3669d3e8e2090dcbbd08f7d1b4112177e7/md-assets/er.png
--------------------------------------------------------------------------------
/md-assets/teacher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/snwjas/OnlineEdu/6c62da3669d3e8e2090dcbbd08f7d1b4112177e7/md-assets/teacher.png
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/OnlineEduApplication.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
6 | import org.springframework.scheduling.annotation.EnableScheduling;
7 |
8 | /**
9 | * Application Entrance
10 | *
11 | * @author Myles Yang
12 | * @date 2021-05-01
13 | */
14 | @EnableScheduling
15 | @ConfigurationPropertiesScan("xyz.refrain.onlineedu.config.properties")
16 | @SpringBootApplication
17 | public class OnlineEduApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(OnlineEduApplication.class, args);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/annotation/AccessLimit.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 接口防刷限流(固定时间内最大访问次数)
10 | *
11 | * @author Myles Yang
12 | */
13 | @Target({ElementType.METHOD})
14 | @Retention(RetentionPolicy.RUNTIME)
15 | public @interface AccessLimit {
16 |
17 | /**
18 | * 最大访问次数
19 | */
20 | int maxCount() default Integer.MAX_VALUE;
21 |
22 | /**
23 | * 固定时间
24 | */
25 | int seconds() default 1;
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/annotation/ActionRecord.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 | import xyz.refrain.onlineedu.aspect.ActionRecordAspect;
5 |
6 | import java.lang.annotation.ElementType;
7 | import java.lang.annotation.Retention;
8 | import java.lang.annotation.RetentionPolicy;
9 | import java.lang.annotation.Target;
10 |
11 | /**
12 | * 操作记录
13 | *
14 | * @author Myles Yang
15 | */
16 | @Target({ElementType.METHOD})
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface ActionRecord {
19 |
20 | /**
21 | * 操作内容的EL表达式,仅支持方法参数
22 | */
23 | @AliasFor("content")
24 | String value() default "";
25 |
26 | /**
27 | * 操作内容,与 value 互为别名
28 | */
29 | @AliasFor("value")
30 | String content() default "";
31 |
32 | /**
33 | * 操作类型
34 | */
35 | // LogType type() default LogType.COMMON;
36 |
37 | /**
38 | * 生效条件的EL表达式
39 | * 它是通过返回值判断,返回值符号为{@link ActionRecordAspect#METHOD_RETURNING_SIGN}
40 | * 示例(函数返回值为0):
41 | * EL表达式:"#ret > 0",结果 false
42 | */
43 | String condition() default "";
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/annotation/TimeCost.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 方法执行计时
10 | */
11 | @Target(ElementType.METHOD)
12 | @Retention(RetentionPolicy.RUNTIME)
13 | public @interface TimeCost {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/aspect/ActionRecordAspect.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.aspect;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.aspectj.lang.JoinPoint;
5 | import org.aspectj.lang.annotation.AfterReturning;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Pointcut;
8 | import org.aspectj.lang.reflect.MethodSignature;
9 | import org.springframework.expression.EvaluationContext;
10 | import org.springframework.expression.ExpressionParser;
11 | import org.springframework.expression.spel.standard.SpelExpressionParser;
12 | import org.springframework.expression.spel.support.StandardEvaluationContext;
13 | import org.springframework.stereotype.Component;
14 | import org.springframework.util.StringUtils;
15 | import xyz.refrain.onlineedu.annotation.ActionRecord;
16 |
17 | import java.lang.reflect.Method;
18 | import java.util.Objects;
19 |
20 | /**
21 | * 操作记录注解切面
22 | *
23 | * @author Myles Yang
24 | */
25 | @Component
26 | @Aspect
27 | @Slf4j
28 | public class ActionRecordAspect {
29 |
30 | /**
31 | * 方法返回值符号
32 | */
33 | public static final String METHOD_RETURNING_SIGN = "ret";
34 |
35 | /**
36 | * el 表达式 解析器
37 | */
38 | private static final ExpressionParser SPEL_PARSER = new SpelExpressionParser();
39 |
40 | @Pointcut("@annotation(xyz.refrain.onlineedu.annotation.ActionRecord)")
41 | public void pointCut() {
42 | }
43 |
44 | /**
45 | * 方法正常返回的advice
46 | *
47 | * @param point 方法的连接点
48 | * @param ret 函数返回值,void的返回值为null
49 | */
50 | @AfterReturning(value = "pointCut()", returning = METHOD_RETURNING_SIGN, argNames = "point,ret")
51 | public void afterReturning(JoinPoint point, Object ret) {
52 |
53 | MethodSignature signature = (MethodSignature) point.getSignature();
54 | Method method = signature.getMethod();
55 | ActionRecord annotation = method.getAnnotation(ActionRecord.class);
56 | // 条件判断是否执行日志记录
57 | if (StringUtils.hasText(annotation.condition())) {
58 | try {
59 | Boolean condition = (Boolean) spell(annotation.condition(),
60 | new String[]{METHOD_RETURNING_SIGN}, new Object[]{ret});
61 | if (!(Objects.nonNull(condition) && condition)) {
62 | return;
63 | }
64 | } catch (Exception e) {
65 | log.error("条件EL表达式解析错误:{}", annotation.condition());
66 | e.printStackTrace();
67 | return;
68 | }
69 | }
70 |
71 | // 测试时 @AliasFor 失效,原因未知
72 | String content = StringUtils.hasText(annotation.value())
73 | ? annotation.content()
74 | : annotation.value();
75 |
76 | if (StringUtils.hasText(content)) {
77 | try {
78 | String cont = (String) spell(content,
79 | signature.getParameterNames(), point.getArgs());
80 | log.info(cont);
81 | } catch (Exception e) {
82 | log.error("内容EL表达式解析错误:{}", content);
83 | e.printStackTrace();
84 | return;
85 | }
86 | }
87 |
88 | }
89 |
90 | /**
91 | * el表达式解析
92 | *
93 | * @param el 表达式
94 | * @param names 参数名称数组
95 | * @param args 参数数组
96 | */
97 | public Object spell(String el, String[] names, Object[] args) {
98 | EvaluationContext context = new StandardEvaluationContext();
99 | for (int i = 0; i < args.length; i++) {
100 | context.setVariable(names[i], args[i]);
101 | }
102 | return SPEL_PARSER.parseExpression(el).getValue(context);
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/aspect/TimeCostAspect.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.aspect;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.aspectj.lang.JoinPoint;
5 | import org.aspectj.lang.annotation.AfterReturning;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Before;
8 | import org.aspectj.lang.annotation.Pointcut;
9 | import org.aspectj.lang.reflect.MethodSignature;
10 | import org.springframework.core.annotation.Order;
11 | import org.springframework.stereotype.Component;
12 |
13 | import java.lang.reflect.Method;
14 | import java.time.Instant;
15 | import java.time.temporal.ChronoUnit;
16 | import java.util.Objects;
17 |
18 | /**
19 | * 方法执行计时注解切面
20 | */
21 | @Component
22 | @Aspect
23 | @Slf4j
24 | @Order(1)
25 | public class TimeCostAspect {
26 |
27 | private final ThreadLocal instantThreadLocal = new ThreadLocal<>();
28 |
29 |
30 | @Pointcut("@annotation(xyz.refrain.onlineedu.annotation.TimeCost)")
31 | public void pointCut() {
32 | }
33 |
34 | @Before("pointCut()")
35 | public void before() {
36 | instantThreadLocal.set(Instant.now());
37 | }
38 |
39 | @AfterReturning("pointCut()")
40 | public void afterReturning(JoinPoint point) {
41 | if (Objects.nonNull(instantThreadLocal.get())) {
42 | Instant now = Instant.now();
43 | MethodSignature signature = (MethodSignature) point.getSignature();
44 | Method method = signature.getMethod();
45 | // String methodParameterTypes = StringUtils.join(method.getGenericParameterTypes(), ", ");
46 | log.info("类:{},方法:{},执行耗时:{}毫秒",
47 | method.getDeclaringClass().getName(),
48 | method.getName() /*+ "(" + methodParameterTypes + ")"*/,
49 | ChronoUnit.MILLIS.between(instantThreadLocal.get(), now));
50 | instantThreadLocal.remove();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/config/AliyunConfig.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.config;
2 |
3 | import com.aliyun.oss.OSS;
4 | import com.aliyun.oss.OSSClientBuilder;
5 | import com.aliyuncs.DefaultAcsClient;
6 | import com.aliyuncs.profile.DefaultProfile;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 | import xyz.refrain.onlineedu.config.properties.AliyunOssProperties;
11 | import xyz.refrain.onlineedu.config.properties.AliyunProperties;
12 | import xyz.refrain.onlineedu.config.properties.AliyunVodProperties;
13 |
14 | /**
15 | * Aliyun Config
16 | *
17 | * @author Myles Yang
18 | */
19 | @Configuration
20 | public class AliyunConfig {
21 |
22 | @Autowired
23 | private AliyunProperties aliyunProperties;
24 |
25 | @Autowired
26 | private AliyunOssProperties aliyunOssProperties;
27 |
28 | @Autowired
29 | private AliyunVodProperties aliyunVodProperties;
30 |
31 | @Bean
32 | public OSS ossClient() {
33 | return new OSSClientBuilder().build(
34 | aliyunOssProperties.getEndpoint(),
35 | aliyunProperties.getAccessKeyId(),
36 | aliyunProperties.getAccessKeySecret()
37 | );
38 | }
39 |
40 | @Bean
41 | public DefaultAcsClient vodClient() {
42 | DefaultProfile vodProfile = DefaultProfile.getProfile(
43 | aliyunVodProperties.getRegionId(),
44 | aliyunProperties.getAccessKeyId(),
45 | aliyunProperties.getAccessKeySecret()
46 | );
47 | return new DefaultAcsClient(vodProfile);
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/config/HibernateValidationConfig.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.config;
2 |
3 | import org.hibernate.validator.HibernateValidator;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
7 |
8 | import javax.validation.Validation;
9 | import javax.validation.Validator;
10 | import javax.validation.ValidatorFactory;
11 |
12 | /**
13 | * Spring Validation 配置
14 | *
15 | * @author Myles Yang
16 | */
17 | @Configuration
18 | public class HibernateValidationConfig {
19 |
20 | /**
21 | * 开启Fail Fast模式,一旦校验失败就立即返回
22 | * Spring Validation 默认会校验完所有字段,然后才抛出异常。
23 | */
24 | @Bean
25 | public Validator validator() {
26 | ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
27 | .configure()
28 | .failFast(true)
29 | .buildValidatorFactory();
30 | return validatorFactory.getValidator();
31 | }
32 |
33 | /**
34 | * 方法参数检验,注意在类上添加 @Validated 注解
35 | */
36 | @Bean
37 | public MethodValidationPostProcessor methodValidationPostProcessor() {
38 | MethodValidationPostProcessor postProcessor = new MethodValidationPostProcessor();
39 | // 设置validator模式为快速失败返回
40 | postProcessor.setValidator(validator());
41 | return postProcessor;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/config/LocalDateTimeSerializerConfig.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.config;
2 |
3 | import com.fasterxml.jackson.databind.DeserializationFeature;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import com.fasterxml.jackson.databind.SerializationFeature;
6 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
7 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
8 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
9 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
10 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
11 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
12 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
13 | import org.springframework.context.annotation.Bean;
14 | import org.springframework.context.annotation.Configuration;
15 | import org.springframework.context.annotation.Primary;
16 |
17 | import java.text.SimpleDateFormat;
18 | import java.time.LocalDate;
19 | import java.time.LocalDateTime;
20 | import java.time.LocalTime;
21 | import java.time.format.DateTimeFormatter;
22 | import java.util.List;
23 |
24 | /**
25 | * 请求、响应 日期格式全局格式化
26 | */
27 | @Configuration
28 | public class LocalDateTimeSerializerConfig {
29 |
30 | public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
31 |
32 | public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
33 |
34 | public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
35 |
36 |
37 | /**
38 | * 自定义 LocalDateTime、LocalDate、LocalTime 的序列化 与 反序列化
39 | * 配置 MappingJackson2HttpMessageConverter{@link WebMvcConfig#customJackson2HttpMessageConverter()}
40 | * 重写 WebMVC 的 configureMessageConverters{@link WebMvcConfig#configureMessageConverters(List)}
41 | */
42 | @Bean
43 | @Primary
44 | public ObjectMapper objectMapper() {
45 |
46 | ObjectMapper om = new ObjectMapper();
47 | om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
48 | om.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
49 |
50 | JavaTimeModule module = new JavaTimeModule();
51 | module
52 | .addSerializer(LocalDateTime.class,
53 | new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)))
54 | .addSerializer(LocalDate.class,
55 | new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)))
56 | .addSerializer(LocalTime.class,
57 | new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)))
58 | .addDeserializer(LocalDateTime.class,
59 | new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)))
60 | .addDeserializer(LocalDate.class,
61 | new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)))
62 | .addDeserializer(LocalTime.class,
63 | new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
64 |
65 | om.registerModule(module);
66 |
67 | om.setDateFormat(new SimpleDateFormat(DEFAULT_DATE_TIME_PATTERN));
68 |
69 | return om;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/config/MyBatisPlusConfig.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.config;
2 |
3 | import com.baomidou.mybatisplus.annotation.DbType;
4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
6 | import org.mybatis.spring.annotation.MapperScan;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.transaction.annotation.EnableTransactionManagement;
10 |
11 | @Configuration
12 | @EnableTransactionManagement
13 | @MapperScan("xyz.refrain.onlineedu.mapper")
14 | public class MyBatisPlusConfig {
15 |
16 | /**
17 | * MybatisPlus 拦截器
18 | */
19 | @Bean
20 | public MybatisPlusInterceptor mybatisPlusInterceptor() {
21 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
22 |
23 | // 注册分页插件
24 | PaginationInnerInterceptor pii = new PaginationInnerInterceptor(DbType.MYSQL);
25 | // 最大单页限制数量
26 | pii.setMaxLimit(100L);
27 |
28 | interceptor.addInnerInterceptor(pii);
29 | return interceptor;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/xyz/refrain/onlineedu/config/RedisConfig.java:
--------------------------------------------------------------------------------
1 | package xyz.refrain.onlineedu.config;
2 |
3 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
4 | import com.fasterxml.jackson.annotation.JsonInclude;
5 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
6 | import com.fasterxml.jackson.annotation.PropertyAccessor;
7 | import com.fasterxml.jackson.databind.ObjectMapper;
8 | import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.data.redis.connection.RedisConnectionFactory;
12 | import org.springframework.data.redis.core.RedisTemplate;
13 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
14 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
15 | import org.springframework.data.redis.serializer.StringRedisSerializer;
16 |
17 | @Configuration
18 | public class RedisConfig {
19 |
20 | @Bean
21 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
22 | RedisTemplate template = new RedisTemplate<>();
23 | template.setConnectionFactory(factory);
24 |
25 | //解决Redis key的序列化方式
26 | StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
27 | template.setKeySerializer(stringRedisSerializer);
28 | template.setHashKeySerializer(stringRedisSerializer);
29 |
30 | // 配置序列化方式
31 | Jackson2JsonRedisSerializer