Skip to content

Commit

Permalink
mapper修改
Browse files Browse the repository at this point in the history
  • Loading branch information
qwbzjy committed Aug 22, 2022
2 parents 398881a + c836a0c commit 15155db
Show file tree
Hide file tree
Showing 53 changed files with 2,424 additions and 19 deletions.
39 changes: 38 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<description>demo_test</description>
<properties>
<java.version>1.8</java.version>
<skiTest>true</skiTest>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -74,14 +75,50 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.7</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.aspectj</groupId>-->
<!-- <artifactId>aspectjweaver</artifactId>-->
<!-- <version>1.9.4</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- lettuce pool 缓存连接池-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>


</dependencies>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/example/demo_test/DemoTestApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableAsync
@EnableScheduling
//@Import({TestImportA.class, TestImportB.class})
//@Import(TestImportConfig.class)
@TestImport
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/example/demo_test/aop/Action.java
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();
}
48 changes: 48 additions & 0 deletions src/main/java/com/example/demo_test/aop/LogAspect.java
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 src/main/java/com/example/demo_test/common/ResponseCode.java
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;

}
25 changes: 25 additions & 0 deletions src/main/java/com/example/demo_test/common/Result.java
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 src/main/java/com/example/demo_test/config/AspectConfig.java
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 src/main/java/com/example/demo_test/config/HttpPoolProperties.java
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 src/main/java/com/example/demo_test/config/RedisConfig.java
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 src/main/java/com/example/demo_test/config/WebMvcConfig.java
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);
}
}
Loading

0 comments on commit 15155db

Please sign in to comment.