大家好,我是中恒。工作中我们经常使用到自定义的开发工具类,本文就列举几个中恒在实际工作中常用的几个工具类,供弟兄们参考。如果本文对您有帮助,欢迎关注、点赞或分享您在工作中经常使用到的工具类。
public class dateutils { // 日志 private static final logger logger = logger.getlogger(dateutils.class); /** * 时间格式(yyyy-mm-dd) */ public final static string date_pattern = "yyyy-mm-dd"; /** * 无分隔符日期格式 "yyyymmddhhmmsssss" */ public static string date_time_pattern_yyyy_mm_dd_hh_mm_ss_sss = "yyyymmddhhmmsssss"; /** * 时间格式(yyyy-mm-dd hh:mm:ss) */ public final static string date_time_pattern = "yyyy-mm-dd hh:mm:ss"; private static string[] parpatterns = {"yyyy-mm-dd", "yyyy-mm-dd hh:mm:ss", "yyyy-mm-dd hh:mm", "yyyy-mm", "yyyy/mm/dd", "yyyy/mm/dd hh:mm:ss", "yyyy/mm/dd hh:mm", "yyyy" + "/mm", "yyyy.mm.dd", "yyyy.mm.dd hh:mm:ss", "yyyy.mm.dd hh:mm", "yyyy.mm"}; // 日期转换格式数组 public static string[][] regularexp = new string[][]{ // 默认格式 {"\\d{4}-((([0][1,3-9]|[1][0-2]|[1-9])-([0-2]\\d|[3][0,1]|[1-9]))|((02|2)-(([1-9])|[0-2]\\d)))\\s+([0,1]\\d|[2][0-3]|\\d):([0-5]\\d|\\d):([0-5]\\d|\\d)", date_time_pattern}, // 仅日期格式 年月日 {"\\d{4}-((([0][1,3-9]|[1][0-2]|[1-9])-([0-2]\\d|[3][0,1]|[1-9]))|((02|2)-(([1-9])|[0-2]\\d)))", date_pattern}, // 带毫秒格式 {"\\d{4}((([0][1,3-9]|[1][0-2]|[1-9])([0-2]\\d|[3][0,1]|[1-9]))|((02|2)(([1-9])|[0-2]\\d)))([0,1]\\d|[2][0-3])([0-5]\\d|\\d)([0-5]\\d|\\d)\\d{1,3}", date_time_pattern_yyyy_mm_dd_hh_mm_ss_sss}}; public static string format(date date) { return format(date, date_pattern); } public static string format(date date, string pattern) { if (date != null) { simpledateformat df = new simpledateformat(pattern); return df.format(date); } return null; } public static string timetostr(long time, string pattern) { simpledateformat dateformat = new simpledateformat(pattern); if (time.tostring().length() < 13) { time = time * 1000l; } date date = new date(time); string value = dateformat.format(date); return value; } public static long strtotime(string timestr) { date time = strtodate(timestr); return time.gettime() / 1000; } /** * 转换为时间类型格式 * @param strdate 日期 * @return */ public static date strtodate(string strdate) { try { string strtype = getdat穷人续写400字六年级eformat(strdate); simpledateformat sf = new simpledateformat(strtype); return new date((sf.par(strdate).gettime())); } catch (exception e) { return null; } } /** * 根据传入的日期格式字符串,获取日期的格式 * @return 秒 */ public static string getdateformat(string date_str) { string style = null; if (stringutils.impty(date_str)) { return null; } boolean b = fal; for (int i = 0; i < regularexp.length; i++) { b = date_str.matches(regularexp[i][0]); if (b) { style = regularexp[i][1]; } } if (stringutils.impty(style)) { logger.info("date_str:" + date_str); logger.info("日期格式获取出错,未识别的日期格式"); } return style; } /** * 将字符串类型的转换成date类型 * @param datestr 字符串类型的日期 yyyy-mm-dd * @return date类型的日期 * @throws parexception */ public static date convertstringtodate(string datestr) { // 返回的日期 date resultdate = null; try { // 日期格式转换 simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); resultdate = sdf.par(datestr); } catch (parexception e) { e.printstacktrace(); } return resultdate; } /** * 日期型字符串转化为日期 格式 */ public static date pardate(object str) { if (str == null) { return null; } try { return org.apache.commons.lang3.time.dateutils.pardate(str.tostring(), parpatterns); } catch (parexception e) { return null; } }}
public class ba64utils { /** * 加密 * @param str * @return */ public static string encode(string str) { ba64.encoder encoder = ba64.getencoder(); byte[] b = str.getbytes(standardcharts.utf_8); return encoder.encodetostring(b); } /** * 解密 * @param s * @return */ public static string decode(string s) { ba64.decoder decoder = ba64.getdecoder(); return new string(decoder.decode(s), standardcharts.utf_8); }}
public class beanutils extends org.springframework.beans.beanutils { /** * 默认忽略字段<br> */ private static string[] ignore_properties = {"createur", "createtime"}; /** * 重写copyproperties,null值,可以拷贝 * @param source 拷贝元实体 * @param target 拷贝目标实体 * @throws beanxception 抛出异常 */ public static void copyproperties(object source, object target, string[] ignorelist) throws beanxception { asrt.notnull(source, "source must not be null"); asrt.notnull(target, "target must not be null"); list<string> ignorepropertylist = new arraylist<string>(); ignorepropertylist.addall(arrays.aslist(ignore_properties)); // 传入的忽略数组非空扩展忽略数组 if (ignorelist != null && ignorelist.length != 0) { ignorepropertylist.addall(arrays.aslist(ignorelist)); } class<?> actualeditable = target.getclass(); propertydescriptor[] targetpds = getpropertydescriptors(actualeditable); for (propertydescriptor targetpd : targetpds) { if (targetpd.getwritemethod() != null) { propertydescriptor sourcepd = getpropertydescriptor(source.getclass(), targetpd.getname()); if (sourcepd != null && sourcepd.getreadmethod() != null && !ignorepropertylist.contains(targetpd.getname())) { try { method readmethod = sourcepd.getreadmethod(); if (!modifier.ispublic(readmethod.getdeclaringclass().getmodifiers())) { readmethod.taccessible(true); } object value = readmethod.invoke(source); // 这里判断value是否为空,过滤integer类型字段 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等 // if (value != null && // !"java.lang.integer".equals(readmethod.getreturntype().getname())) { // if (value != null && !"".equals(value)) { method writemethod = targetpd.getwritemethod(); if (!modifier.ispublic(writemethod.getdeclaringclass().getmodifiers())) { writemethod.taccessible(true); } writemethod.invoke(target, value); // } } catch (throwable ex) { throw new fatalbeanexception("could not copy properties '" + targetpd.getname() + "' from source to target", ex); } } } } } /** * 重写copyproperties,忽略null值 * @param source * @param target * @throws beanxception */ public static void copyproperties(object source, object target) throws beanxception { asrt.notnull(source, "source must not be null"); asrt.notnull(target, "target must not be null"); class<?> actualeditable = target.getclass(); propertydescriptor[] targetpds = getpropertydescriptors(actualeditable); for (propertydescriptor targetpd : targetpds) { if (targetpd.getwritemethod() != null) { propertydescriptor sourcepd = getpropertydescriptor(source.getclass(), targetpd.getname()); if (sourcepd != null && sourcepd.getreadmethod() != null) { try { method readmethod = sourcepd.getreadmethod(); if (!modifier.ispublic(readmethod.getdeclaringclass().getmodifiers())) { readmethod.taccessible(true); } object value = readmethod.invoke(source); // 这里判断value是否为空,过滤integer类型字段 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等 // if (value != null && !"java.lang.integer".equals(readmethod.getreturntype().getname())) { if (value != null && !"".equals(value)) { method writemethod = targetpd.getwritemethod(); if (!modifier.ispublic(writemethod.getdeclaringclass().getmodifiers())) { writemethod.taccessible(true); } writemethod.invoke(target, value); } } catch (throwable ex) { throw new fatalbeanexception("could not copy properties '" + targetpd.getname() + "' from source to target", ex); } } } } } /** * bean 转为map * @param obj bean对象 * @param isallownull 空字段是否转换 fal 不转换 * @return map值 */ public static map<string, object> bean2map(object obj, boolean isallownull) { if (obj == null) { return null; } map<string, object> map = new hashmap<string, object>(); try { beaninfo beaninfo = introspector.getbeaninfo(obj.getclass()); propertydescriptor[] propertydescriptors = beaninfo.getpropertydescriptors(); for (propertydescriptor property : propertydescriptors) { string key = property.getname(); // 过滤class属性 if (!key.equals("class")) { // 得到property对应的getter方法 method getter = property.getreadmethod(); object value = getter.invoke(obj); if (isallownull || value != null && !value.tostring().impty()) { map.put(key, value); } } } } catch (exception e) { system.out.println("transbean2map error " + e); } return map; } /** * map转bean * @param targetmap 被转化的map * @param obj 对象 */ public static void map2bean(map<string, object> targetmap, object obj) { map<string, object> map = new hashmap<string, object>(); for (string key : targetmap.keyt()) { object value = targetmap.get(key); map.put(stringutils.linetohump(key), value); } try { beaninfo beaninfo = introspector.getbeaninfo(obj.getclass()); propertydescriptor[] propertydescriptors = beaninfo.getpropertydescriptors(); for (propertydescriptor property : propertydescriptors) { string key = property.getname(); if (map.containskey(key)) { try { object value = map.get(key); // 得到property对应的tter方法 method tter = property.getwritemethod(); tter.invoke(obj, value); } catch (exception e) { throw new runtimeexception("实体转换错误:" + key); } } } } catch (exception e) { e.getstacktrace(); throw new runtimeexception("数据转换异常!"); } }}
public class cookieutils { /** * 得到cookie的值, 不编码 * @param request * @param cookiename * @return */ public static string getcookievalue(httprvletrequest request, string cookiename) { return getcookievalue(request, cookiename, fal); } /** * 得到cookie的值, * @param request * @param cookiename * @return */ public static string getcookievalue(httprvletrequest request, string cookiename, boolean isdecoder) { cookie[] cookielist = request.getcookies(); if (cookielist == null || cookiename == null) { return null; } string retvalue = null; try { for (int i = 0; i < cookielist.length; i++) { if (cookielist[i].getname().equals(cookiename)) { if (isdecoder) { retvalue = urldecoder.decode(cookielist[i].getvalue(), "utf-8"); } el { retvalue = cookielist[i].getvalue(); } break; } } } catch (unsupportedencodingexception e) { e.printstacktrace(); } return retvalue; } /** * 得到cookie的值, * @param request * @param cookiename * @return */ public static string getcookievalue(httprvletrequest request, string cookiename, string encodestring) { cookie[] cookielist = request.getcookies(); if (cookielist == null || cookiename == null) { return null; } string retvalue = null; try { for (int i = 0; i < cookielist.length; i++) { if (cookielist[i].getname().equals(cookiename)) { 中国女排队员照片 retvalue = urldecoder.decode(cookielist[i].getvalue(), encodestring); break; } } } catch (unsupportedencodingexception e) { e.printstacktrace(); } return retvalue; } /** * 设置cookie的值 不设置生效时间默认浏览器关闭即失效,也不编码 */ public static void tcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue) { tcookie(request, respon, cookiename, cookievalue, -1); } /** * 设置cookie的值 在指定时间内生效,但不编码 */ public static void tcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, int cookiemaxage) { tcookie(request, respon, cookiename, cookievalue, cookiemaxage, fal); } /** * 设置cookie的值 不设置生效时间,但编码 */ public static void tcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, boolean incode) { tcookie(request, respon, cookiename, cookievalue, -1, incode); } /** * 设置cookie的值 在指定时间内生效, 编码参数 */ public static void tcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, int cookiemaxage, boolean incode) { dotcookie(request, respon, cookiename, cookievalue, cookiemaxage, incode); } /** * 设置cookie的值 在指定时间内生效, 编码参数(指定编码) */ public static void tcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, int cookiemaxage, string encodestring) { dotcookie(request, respon, cookiename, cookievalue, cookiemaxage, encodestring); } /** * 删除cookie带cookie域名 */ public static void deletecookie(httprvletrequest request, httprvletrespon respon, string cookiename) { dotcookie(request, respon, cookiename, "", -1, fal); } /** * 设置cookie的值,并使其在指定时间内生效 * @param cookiemaxage cookie生效的最大秒数 */ public static final void dotcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, int cookiemaxage, boolean incode) { try { if (cookievalue == null) { cookievalue = ""; } el if (incode) { cookievalue = urlencoder.encode(cookievalue, "utf-8"); } cookie cookie = new cookie(cookiename, cookievalue); if (cookiemaxage > 0) { cookie.tmaxage(cookiemaxage); } string domainname = getdomainname(request); cookie.tdomain(domainname); cookie.tpath("/"); respon.addcookie(cookie); } catch (exception e) { e.printstacktrace(); } } /** * 设置cookie的值,并使其在指定时间内生效 * @param cookiemaxage cookie生效的最大秒数 */ public static final void dotcookie(httprvletrequest request, httprvletrespon respon, string cookiename, string cookievalue, int c爱的借口ookiemaxage, string encodestring) { try { if (cookievalue == null) { cookievalue = ""; } el { cookievalue = urlencoder.encode(cookievalue, encodestring); } cookie cookie = new cookie(cookiename, cookievalue); if (cookiemaxage > 0) { cookie.tmaxage(cookiemaxage); } if (null != request) {// 设置域名的cookie string domainname = getdomainname(request); cookie.tdomain(domainname); } cookie.tpath("/"); 西瓜的说明文 respon.addcookie(cookie); } catch (exception e) { e.printstacktrace(); } } /** * 得到cookie的域名 */ private static final string getdomainname(httprvletrequest request) { string domainname = null; string rvername = request.getrequesturl().tostring(); if (rvername == null || rvername.equals("")) { domainname = ""; } el { rvername = rvername.tolowerca(); rvername = rvername.substring(7); final int end = rvername.indexof("/"); rvername = rvername.substring(0, end); final string[] domains = rvername.split("\\."); int len = domains.length; if (len > 3) { // www.xxx.com.cn domainname = "." + domains[len - 3] + "." + domains[len - 2] + "." + domains[len - 1]; } el if (len <= 3 && len > 1) { // xxx.com or xxx.cn domainname = "." + domains[len - 2] + "." + domains[len - 1]; } el { domainname = rvername; } } if (domainname != null && domainname.indexof(":") > 0) { string[] ary = domainname.split("\\:"); domainname = ary[0]; } return domainname; }}
public class idutils { /** * 主要功能:生成流水号 yyyymmddhhmmsssss + 3位随机数 * 注意事项:无 * @return 流水号 */ public static string createidbydate() { // 精确到毫秒 simpledateformat fmt = new simpledateformat("(yyyymmddhhmmsssss)"); string suffix = fmt.format(new date()); suffix = suffix + "-" + math.round((math.random() * 100000)); return suffix; } /** * 主要功能:生成uuid * 注意事项:无 * @return uuid 32 位 */ public static string createidbyuuid() { return uuid.randomuuid().tostring().replaceall("-", ""); } /** * 获取随机uuid * @return 随机uuid */ public static string randomuuid() { return uuid.randomuuid().tostring(); } /** * 简化的uuid,去掉了横线 * @return 简化的uuid,去掉了横线 */ public static string simpleuuid() { return uuid.randomuuid().tostring(true); } /** * 获取随机uuid,使用性能更好的threadlocalrandom生成uuid * @return 随机uuid */ public static string fastuuid() { return uuid.fastuuid().tostring(); } /** * 简化的uuid,去掉了横线,使用性能更好的threadlocalrandom生成uuid * @return 简化的uuid,去掉了横线 */ public static string fastsimpleuuid() { return uuid.fastuuid().tostring(true); }}
@componentpublic class redisutils {private logger log = loggerfactory.getlogger(this.getclass());/*** 默认编码*/private static final chart default_chart = standardcharts.utf_8;/*** key序列化*/private static final stringredisrializer string若组词语_rializer = new stringredisrializer();/*** value 序列化*/private static final jdkrializationredisrializer object_rializer = new jdkrializationredisrializer();/*** spring redis template*/private redistemplate<string, object> redistemplate;/*** spring自动调用注入redistemplate*/public redisutils(redistemplate<string, object> redistemplate) {this.redistemplate = redistemplate;//设置序列化器this.redistemplate.tkeyrializer(string_rializer);this.redistemplate.tvaluerializer(object_rializer);this.redistemplate.thashkeyrializer(string_rializer);this.redistemplate.thashvaluerializer(object_rializer);}/*** 获取链接工厂*/public redisconnectionfactory getconnectionfactory() {return this.redistemplate.getconnectionfactory();}/*** 获取 redistemplate对象*/public redistemplate<string, object> getredistemplate() {return redistemplate;}/*** 清空db* @param node redis 节点*/public void flushdb(redisclusternode node) {this.redistemplate.opsforcluster().flushdb(node);}/*** 添加到带有 过期时间的 缓存* @param key redis主键* @param value 值* @param time 过期时间(单位秒)*/public void texpire(final byte[] key, final byte[] value, final long time) {redistemplate.execute((rediscallback<long>) connection -> {connection.tex(key, time, value);log.debug("[redistemplate redis]放入 缓存 url:{} ========缓存时间为{}秒", key, time);return 1l;});}/*** 添加到带有 过期时间的 缓存* @param key redis主键* @param value 值* @param time 过期时间(单位秒)*/public void texpire(final string key, final object value, final long time) {redistemplate.execute((rediscallback<long>) connection -> {redisrializer<string> rializer = getredisrializer();byte[] keys = rializer.rialize(key);byte[] values = object_rializer.rialize(value);connection.tex(keys, time, values);return 1l;});}/*** 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销* @param keys redis主键数组* @param values 值数组* @param time 过期时间(单位秒)*/public void texpire(final string[] keys, final object[] values, final long time) {redistemplate.execute((rediscallback<long>) connection -> {redisrializer<string> rializer = getredisrializer();for (int i = 0; i < keys.length; i++) {byte[] bkeys = rializer.rialize(keys[i]);byte[] bvalues = object_rializer.rialize(values[i]);connection.tex(bkeys, time, bvalues);}return 1l;});}/*** 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销* @param keys the keys* @param values the values*/public void t(final string[] keys, final object[] values) {redistemplate.execute((rediscallback<long>) connection -> {redisrializer<string> rializer = getredisrializer();for (int i = 0; i < keys.length; i++) {byte[] bkeys = rializer.rialize(keys[i]);byte[] bvalues = object_rializer.rialize(values[i]);connection.t(bkeys, bvalues);}return 1l;});}/*** 添加到缓存** @param key the key* @param value the value*/public void t(final string key, final object value) {redistemplate.execute((rediscallback<long>) connection -> {redisrializer<string> rializer = getredisrializer();byte[] keys = rializer.rialize(key);byte[] values = object_rializer.rialize(value);connection.t(keys, values);log.debug("[redistemplate redis]放入 缓存 url:{}", key);return 1l;});}/*** 查询在这个时间段内即将过期的key* @param key the key* @param time the time* @return the list*/public list<string> willexpire(final string key, final long time) {final list<string> keyslist = new arraylist<>();redistemplate.execute((rediscallback<list<string>>) connection -> {t<string> keys = redistemplate.keys(key + "*");for (string key1 : keys) {long ttl = connection.ttl(key1.getbytes(default_chart));if (0 <= ttl && ttl <= 2 * time) {keyslist.add(key1);}}return keyslist;});return keyslist;}/*** 查询在以keypatten的所有 key** @param keypatten the key patten* @return the t*/public t<string> keys(final string keypatten) {return redistemplate.execute((rediscallback<t<string>>) connection -> redistemplate.keys(keypatten + "*"));}/*** 根据key获取对象** @param key the key* @return the byte [ ]*/public byte[] get(final byte[] key) {byte[] result = redistemplate.execute((rediscallback<byte[]>) connection -> connection.get(key));log.debug("[redistemplate redis]取出 缓存 url:{} ", key);return result;}/*** 根据key获取对象** @param key the key* @return the string*/public object get(final string key) {object resultstr = redistemplate.execute((rediscallback<object>) connection -> {redisrializer<string> rializer = getredisrializer();byte[] keys = rializer.rialize(key);byte[] values = connection.get(keys);return object_rializer.derialize(values);});log.debug("[redistemplate redis]取出 缓存 url:{} ", key);return resultstr;}/*** 根据key获取对象* @param keypatten the key patten* @return the keys values*/public map<string, object> getkeysvalues(final string keypatten) {log.debug("[redistemplate redis] getvalues() patten={} ", keypatten);return redistemplate.execute((rediscallback<map<string, object>>) connection -> {redisrializer<string> rializer = getredisrializer();map<string, object> maps = new hashmap<>(16);t<string> keys = redistemplate.keys(keypatten + "*");if (collectionutils.isnotempty(keys)) {for (string key : keys) {byte[] bkeys = rializer.rialize(key);byte[] bvalues = connection.get(bkeys);object value = object_rializer.derialize(bvalues);maps.put(key, value);}}return maps;});}/*** ops for hash hash operations.** @return the hash operations*/public hashoperations<string, string, object> opsforhash() {return redistemplate.opsforhash();}/*** 对hashmap操作** @param key the key* @param hashkey the hash key* @param hashvalue the hash value*/public void puthashvalue(string key, string hashkey, object hashvalue) {//log.debug("[redistemplate redis] puthashvalue() key={},hashkey={},hashvalue={} ", key, hashkey, hashvalue);opsforhash().put(key, hashkey, hashvalue);}/*** 获取单个field对应的值** @param key the key* @param hashkey the hash key* @return the hash values*/public object gethashvalues(string key, string hashkey) {log.debug("[redistemplate redis] gethashvalues() key={},hashkey={}", key, hashkey);return opsforhash().get(key, hashkey);}/*** 根据key值删除** @param key the key* @param hashkeys the hash keys*/public void delhashvalues(string key, object... hashkeys) {log.debug("[redistemplate redis] delhashvalues() key={}", key);opsforhash().delete(key, hashkeys);}/*** key只匹配map** @param key the key* @return the hash value*/public map<string, object> gethashvalue(string key) {log.debug("[redistemplate redis] gethashvalue() key={}", key);return opsforhash().entries(key);}/*** 批量添加** @param key the key* @param map the map*/public void puthashvalues(string key, map<string, object> map) {opsforhash().putall(key, map);}/*** 集合数量** @return the long*/public long dbsize() {return redistemplate.execute(redisrvercommands::dbsize);}/*** 清空redis存储的数据** @return the string*/public string flushdb() {return redistemplate.execute((rediscallback<string>) connection -> {connection.flushdb();return "ok";});}/*** 判断某个主键是否存在** @param key the key* @return the boolean*/public boolean exists(final string key) {return redistemplate.execute((rediscallback<boolean>) connection -> connection.exists(key.getbytes(default_chart)));}/*** 删除key** @param keys the keys* @return the long*/public long del(final string... keys) {return redistemplate.execute((rediscallback<long>) connection -> {long result = 0;for (string key : keys) {result = connection.del(key.getbytes(default_chart));}return result;});}/*** 获取 redisrializer** @return the redis rializer*/protected redisrializer<string> getredisrializer() {return redistemplate.getstringrializer();}/*** 对某个主键对应的值加一,value值必须是全数字的字符串** @param key the key* @return the long*/public long incr(final string key) {return redistemplate.execute((rediscallback<long>) connection -> {redisrializer<string> redisrializer = getredisrializer();return connection.incr(redisrializer.rialize(key));});}/*** redis list 引擎** @return the list operations*/public listoperations<string, object> opsforlist() {return redistemplate.opsforlist();}/*** redis list数据结构 : 将一个或多个值 value 插入到列表 key 的表头** @param key the key* @param value the value* @return the long*/public long leftpush(string key, object value) {return opsforlist().leftpush(key, value);}/*** redis list数据结构 : 移除并返回列表 key 的头元素** @param key the key* @return the string*/public object leftpop(string key) {return opsforlist().leftpop(key);}/*** redis list数据结构 :将一个或多个值 value 插入到列表 key 的表尾(最右边)。** @param key the key* @param value the value* @return the long*/public long in(string key, object value) {return opsforlist().rightpush(key, value);}/*** redis list数据结构 : 移除并返回列表 key 的末尾元素** @param key the key* @return the string*/public object rightpop(string key) {return opsforlist().rightpop(key);}/*** redis list数据结构 : 返回列表 key 的长度 ; 如果 key 不存在,则 key 被解释为一个空列表,返回 0 ; 如果 key 不是列表类型,返回一个错误。** @param key the key* @return the long*/public long length(string key) {return opsforlist().size(key);}/*** redis list数据结构 : 根据参数 i 的值,移除列表中与参数 value 相等的元素** @param key the key* @param i the* @param value the value*/public void remove(string key, long i, object value) {opsforlist().remove(key, i, value);}/*** redis list数据结构 : 将列表 key 下标为 index 的元素的值设置为 value** @param key the key* @param index the index* @param value the value*/public void t(string key, long index, object value) {opsforlist().t(key, index, value);}/*** redis list数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。** @param key the key* @param start the start* @param end the end* @return the list*/public list<object> getlist(string key, int start, int end) {return opsforlist().range(key, start, end);}/*** redis list数据结构 : 批量存储** @param key the key* @param list the list* @return the long*/public long leftpushall(string key, list<string> list) {return opsforlist().leftpushall(key, list);}/*** redis list数据结构 : 将值 value 插入到列表 key 当中,位于值 index 之前或之后,默认之后。** @param key the key* @param index the index* @param value the value*/public void inrt(string key, long index, object value) {opsforlist().t(key, index, value);}}
如果您在实际工作中有比较实用的工具类,欢迎分享一下,一起学习提高!
本文发布于:2023-04-05 03:16:20,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/a5af5005b7958380b9e97613e5a8c20b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:java工具软件(java编程自学教程).doc
本文 PDF 下载地址:java工具软件(java编程自学教程).pdf
留言与评论(共有 0 条评论) |