-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
2,424 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.demo_test.aop; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 14:31 | ||
* @Description | ||
*/ | ||
@Documented | ||
@Retention(value = RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface Action { | ||
String name(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.demo_test.aop; | ||
|
||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.After; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 14:32 | ||
* @Description | ||
*/ | ||
@Aspect | ||
@Component | ||
public class LogAspect { | ||
|
||
@Pointcut("@annotation(com.example.demo_test.aop.Action)") | ||
public void annotationPointCut() { | ||
} | ||
|
||
/** | ||
* @param joinPoint | ||
* @Before 前置通知,在方法执行之前 | ||
*/ | ||
@Before("execution(* com.example.demo_test.controller.*.*(..))") | ||
public void before(JoinPoint joinPoint) { | ||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
System.out.println("方法规则式拦截:" + method.getName()); | ||
} | ||
|
||
/** | ||
* @After 后置通知,在方法执行之后 | ||
* @param joinPoint | ||
*/ | ||
@After("annotationPointCut()") | ||
public void after(JoinPoint joinPoint){ | ||
MethodSignature signature=(MethodSignature)joinPoint.getSignature(); | ||
Method method=signature.getMethod(); | ||
Action action=method.getAnnotation(Action.class); | ||
System.out.println("注解式拦截..."+action.name()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/example/demo_test/common/ResponseCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.demo_test.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 9:41 | ||
* @Description | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public enum ResponseCode { | ||
// 系统模块 | ||
SUCCESS(0, "操作成功"), | ||
ERROR(1, "操作失败"), | ||
SERVER_ERROR(500, "服务器异常"), | ||
|
||
// 通用模块 1xxxx | ||
ILLEGAL_ARGUMENT(10000, "参数不合法"), | ||
REPETITIVE_OPERATION(10001, "请勿重复操作"), | ||
ACCESS_LIMIT(10002, "请求太频繁, 请稍后再试"), | ||
MAIL_SEND_SUCCESS(10003, "邮件发送成功"), | ||
|
||
// 用户模块 2xxxx | ||
NEED_LOGIN(20001, "登录失效"), | ||
USERNAME_OR_PASSWORD_EMPTY(20002, "用户名或密码不能为空"), | ||
USERNAME_OR_PASSWORD_WRONG(20003, "用户名或密码错误"), | ||
USER_NOT_EXISTS(20004, "用户不存在"), | ||
WRONG_PASSWORD(20005, "密码错误"), | ||
|
||
// 文件模块 3xxxx | ||
FILE_EMPTY(30001, "文件不能空"), | ||
FILE_NAME_EMPTY(30002, "文件名称不能为空"), | ||
FILE_MAX_SIZE(30003, "文件大小超出"), | ||
FILE_NO_EXIST(30004, "文件不存在"), | ||
FILE_DOWNLOAD_SUCCESS(30005, "文件下载成功"), | ||
FILE_DOWNLOAD_FAILED(30006, "文件下载失败"), | ||
; | ||
private final Integer code; | ||
private final String msg; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.demo_test.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 9:42 | ||
* @Description | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Result { | ||
|
||
private int code; | ||
private String message; | ||
private Object data; | ||
|
||
public Result(ResponseCode result) { | ||
this.code = result.getCode(); | ||
this.message = result.getMsg(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/example/demo_test/config/AspectConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//package com.example.demo_test.config; | ||
// | ||
//import org.aspectj.lang.ProceedingJoinPoint; | ||
//import org.aspectj.lang.annotation.Around; | ||
//import org.aspectj.lang.annotation.Aspect; | ||
//import org.aspectj.lang.annotation.Pointcut; | ||
//import org.springframework.stereotype.Component; | ||
// | ||
///** | ||
// * @author qiwenbo | ||
// * @date 2022/8/18 17:24 | ||
// * @Description | ||
// */ | ||
//@Component | ||
//@Aspect | ||
//public class AspectConfig { | ||
// | ||
// @Pointcut("execution(* com.example.demo_test..*(..))") | ||
// private void pointcut() { | ||
// | ||
// } | ||
// | ||
// /** | ||
// * 环绕通知 | ||
// * | ||
// * @param joinPoint | ||
// * @return | ||
// * @throws Throwable | ||
// */ | ||
// @Around("pointcut()") | ||
// public Object testAround(ProceedingJoinPoint joinPoint) throws Throwable { | ||
// System.out.println("执行业务前打印日志.............."); | ||
// Object proceed = joinPoint.proceed(); | ||
// System.out.println("执行业务后打印日志.............."); | ||
// return proceed; | ||
// } | ||
//} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/demo_test/config/HttpPoolProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.example.demo_test.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 13:56 | ||
* @Description | ||
*/ | ||
@Component | ||
@ConfigurationProperties(prefix = "http.pool.conn") | ||
@Data | ||
public class HttpPoolProperties { | ||
// 最大连接数 | ||
private Integer maxTotal = 20; | ||
// 同路由并发数 | ||
private Integer defaultMaxPerRoute = 20; | ||
private Integer connectTimeout = 2000; | ||
private Integer connectionRequestTimeout = 2000; | ||
private Integer socketTimeout = 2000; | ||
// 线程空闲多久后进行校验 | ||
private Integer validateAfterInactivity = 2000; | ||
// 重试次数 | ||
private Integer retryTimes = 2; | ||
|
||
// 是否开启充实 | ||
private boolean enableRetry = true; | ||
// 重试的间隔:可实现 ServiceUnavailableRetryStrategy 接口 | ||
private Integer retryInterval = 2000; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/demo_test/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.demo_test.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
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.Jackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 11:50 | ||
* @Description | ||
*/ | ||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Bean | ||
@SuppressWarnings("all") | ||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { | ||
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); | ||
template.setConnectionFactory(factory); | ||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); | ||
ObjectMapper om = new ObjectMapper(); | ||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); | ||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); | ||
jackson2JsonRedisSerializer.setObjectMapper(om); | ||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); | ||
// key采用String的序列化方式 | ||
template.setKeySerializer(stringRedisSerializer); | ||
// hash的key也采用String的序列化方式 | ||
template.setHashKeySerializer(stringRedisSerializer); | ||
// value序列化方式采用jackson | ||
template.setValueSerializer(jackson2JsonRedisSerializer); | ||
// hash的value序列化方式采用jackson | ||
template.setHashValueSerializer(jackson2JsonRedisSerializer); | ||
template.afterPropertiesSet(); | ||
return template; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/demo_test/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.demo_test.config; | ||
|
||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
/** | ||
* @author qiwenbo | ||
* @date 2022/8/19 9:38 | ||
* @Description 解决跨域问题配置类 | ||
*/ | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("*") | ||
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") | ||
.maxAge(3600) | ||
.allowCredentials(true); | ||
} | ||
} |
Oops, something went wrong.