java 缓存接口_Java后端常用工具类、缓存接口封装、消息队列接口封装、第三方支付...

本文介绍了Java后端的常见工具类,包括分布式锁、ES操作、Redis API、安全加密等,并详细讲解了缓存接口的实现,如基于Redis的分布式锁。此外,还涵盖了支付模块的接口设计,如预支付订单生成,以及Web层的数据安全处理,如请求参数的加密和验证。
摘要由CSDN通过智能技术生成

common-project

Java后端常用工具类、缓存接口、消息队列接口、第三方支付接口封装;Restful接口参数验证,错误信息友好提示。

[TOC]

1.分布式锁、分布式方法锁(common-distributed-lock):

DistributedLock类(依赖RedisTemplate接口实现)

/**

*

* @param key 锁标识

* @param attempt 重试次数

* @return

*/

public boolean lock(String key,int attempt);

/**

*

* @param key 锁标识

* @param time 过期时间

* @param timeUnit 过期时间单位

* @param attemptNum 重试次数

* @return

*/

public boolean lock(String key, long time, TimeUnit timeUnit,int attemptNum)

@EnableMethodLock @MethodLock 使用

@EnableMethodLock

在Spring Boot 项目启动类添加该注解开启分布式方法锁

普通Spring项目配置component-scan自动扫描com.yz.common.distributed.lock.configuration包即可

@MethodLock

@Target({ElementType.METHOD})

@Retention(RetentionPolicy.RUNTIME)

@Documented

public @interface MethodLock {

/**

* 锁标识

* @return

*/

String key() default "";

/**

* 时间

* @return

*/

long time() default 10;

/**

* 单位

* @return

*/

TimeUnit timeUnit() default TimeUnit.SECONDS;

/**

* 是否自动解锁

* @return

*/

boolean autoUnLock() default true;

/**

* 重试次数

* @return

*/

int attemptNum() default 0;

}

在需要使用分布式方法锁的method上使用该注解即可

2.ES(common-elasticsearch)

① ElasticSearch 增删改操作

② ElasticSearch 高级查询(链式调用)

3.常用工具类(common-core)

网络类(HttpUtil)

时间类(DateUtils)

JSON类(JsonUtil)

安全类(MD5加密、AES加密、Base64编码、3DES加密、RSA加密、SHA256)

图片处理(GraphicsMagick)

...

4.Redis(common-redis)

①redis常用API接口(RedisUtil)

②基于redis实现分布式锁(RedisLockUtil)

5.支付模块(common-pay)

①使用简单工厂模式实现预支付订单生成(位于com.yz.common.payment.trade.pay包下)

2be9445b3af07b8e25ab57aa8ee06173.png

②使用建造者模式对预支付订单参数进行动态构建(位于com.yz.common.payment.trade.pay.builder包下)

2f814467c6dca3d27b7cda96bae2a0a8.png

③通过ThirdPayFactory工厂类获取PayService

bc65bf0438fd2b994a56e5ab857cd35b.png

④发起预支付订单、退款、订单查询调用

6.common-web

①请求参数转换(非Form表单或get+参数方式):

自定义web拦截器(DataSafeFilter),加密json数据解析为Map保存到HttpServletRequest

中;自定义HttpServletRequest包装类(IHttpServletRequestWrapper),将解析的Map数

据保存到Parameter中

②基于hibernate-validator restful接口参数验证

#import <Foundation/Foundation.h> typedef void(^SuccessBlock)(NSDictionary *returnDic, NSString *msg); typedef void(^FailureBlock)(NSString *errorInfo); typedef void(^LoadProgress)(float progress); @interface CBCacheHttpRequet : NSObject /** * Get请求 不对数据进行缓存 * * @param urlStr url * @param success 成功的回调 * @param failure 失败的回调 */ +(void)getRequestUrlStr:(NSString *)urlStr success:(SuccessBlock)success failure:(FailureBlock)failure; /** * Get请求 对数据进行缓存 * * @param urlStr url * @param success 成功的回调 * @param failure 失败的回调 */ +(void)getRequestCacheUrlStr:(NSString *)urlStr success:(SuccessBlock)success failure:(FailureBlock)failure ; /** * Post请求 不对数据进行缓存 * * @param urlStr url * @param parameters post参数 * @param success 成功的回调 * @param failure 失败的回调 */ +(void)postRequestUrlStr:(NSString *)urlStr withDic:(NSDictionary *)parameters success:(SuccessBlock )success failure:(FailureBlock)failure; /** * Post请求 对数据进行缓存 * * @param urlStr url * @param parameters post参数 * @param success 成功的回调 * @param failure 失败的回调 */ +(void)postRequestCacheUrlStr:(NSString *)urlStr withDic:(NSDictionary *)parameters success:(SuccessBlock )success failure:(FailureBlock)failure; /** * 上传单个文件 * * @param urlStr 服务器地址 * @param parameters 参数 * @param imageStr 上传的key * @param imageData 上传的问件 * @param loadProgress 上传的进度 * @param success 成功的回调 * @param failure 失败的回调 */ +(void)upLoadDataWithUrlStr:(NSString *)urlStr withDic:(NSDictionary *)parameters imageKey:(NSString *)imageStr withImageData:(NSData *)imageData upLoadProgress:(LoadProgress)loadProgress success:(SuccessBlock)success failure:(FailureBlock)failure; //清除接口数据缓存 +(void)deleteCache; @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值