开发笔记

1、jQuery countdown插件

倒计时插件

2、Spring Boot引用js、css文件

https://blog.csdn.net/CureRrzy/article/details/79350356

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.way.spdemo1.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
"classpath:/resources/", "classpath:/static/", "classpath:/public/" };

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
super.addResourceHandlers(registry);
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
}

}

3、Protostuff序列化和反序列化

https://blog.csdn.net/wangfei8348/article/details/60140301
https://www.jianshu.com/p/f017d4518b8f

序列化

1
2
3
4
5
6
7
8
9
10
11
12
13
@SuppressWarnings("unchecked")
public static <T> byte[] serialize(T obj) {
Class<T> cls = (Class<T>) obj.getClass();
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
Schema<T> schema = getSchema(cls);
return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
} finally {
buffer.clear();
}
}

反序列化

1
2
3
4
5
6
7
8
9
10
public static <T> T deserialize(byte[] data, Class<T> cls) {
try {
T message = objenesis.newInstance(cls);
Schema<T> schema = getSchema(cls);
ProtostuffIOUtil.mergeFrom(data, message, schema);
return message;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}

构建schema

1
2
3
4
5
6
7
8
9
10
11
12
private static Map<Class<?>, Schema<?>> cachedSchema = new ConcurrentHashMap<>();

private static <T> Schema<T> getSchema(Class<T> cls) {
Schema<T> schema = (Schema<T>) cachedSchema.get(cls);
if (schema == null) {
schema = RuntimeSchema.createFrom(cls);
if (schema != null) {
cachedSchema.put(cls, schema);
}
}
return schema;
}

4、CommonLang3中的StringUtils方法解析

https://blog.csdn.net/xuxiaoxie/article/details/52095930

1
public static boolean isEmpty(CharSequence cs)

常用函数之一,判断字符串是否为””或者null

1
2
3
4
5
StringUtils.isEmpty(null)      = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
1
public static boolean isNotEmpty(CharSequence cs)

最常用函数之一,跟上面方法相对

1
2
3
4
5
StringUtils.isNotEmpty(null)      = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
1
public static boolean isAnyEmpty(CharSequence... css)

任意一个参数为空的话,返回true,
如果这些参数都不为空的话返回false。

在写一些判断条件的时候,这个方法还是很实用的。

1
2
3
4
5
6
7
StringUtils.isAnyEmpty(null)             = true
StringUtils.isAnyEmpty(null, "foo") = true
StringUtils.isAnyEmpty("", "bar") = true
StringUtils.isAnyEmpty("bob", "") = true
StringUtils.isAnyEmpty(" bob ", null) = true
StringUtils.isAnyEmpty(" ", "bar") = false
StringUtils.isAnyEmpty("foo", "bar") = false
1
public static boolean isNoneEmpty(CharSequence... css)

任意一个参数是空,返回false
所有参数都不为空,返回true

注意这些方法的用法

1
2
3
4
5
6
7
StringUtils.isNoneEmpty(null)             = false
StringUtils.isNoneEmpty(null, "foo") = false
StringUtils.isNoneEmpty("", "bar") = false
StringUtils.isNoneEmpty("bob", "") = false
StringUtils.isNoneEmpty(" bob ", null) = false
StringUtils.isNoneEmpty(" ", "bar") = true
StringUtils.isNoneEmpty("foo", "bar") = true
1
public static boolean isBlank(CharSequence cs)

判断字符对象是不是空字符串,注意与isEmpty的区别

1
2
3
4
5
StringUtils.isBlank(null)      = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
1
public static boolean isNotBlank(CharSequence cs)
1
2
3
4
5
StringUtils.isNotBlank(null)      = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true

原理同上

1
public static boolean isAnyBlank(CharSequence... css)
1
2
3
4
5
6
7
8
StringUtils.isAnyBlank(null)             = true
StringUtils.isAnyBlank(null, "foo") = true
StringUtils.isAnyBlank(null, null) = true
StringUtils.isAnyBlank("", "bar") = true
StringUtils.isAnyBlank("bob", "") = true
StringUtils.isAnyBlank(" bob ", null) = true
StringUtils.isAnyBlank(" ", "bar") = true
StringUtils.isAnyBlank("foo", "bar") = false
1
public static boolean isNoneBlank(CharSequence... css)
1
2
3
4
5
6
7
8
StringUtils.isNoneBlank(null)             = false
StringUtils.isNoneBlank(null, "foo") = false
StringUtils.isNoneBlank(null, null) = false
StringUtils.isNoneBlank("", "bar") = false
StringUtils.isNoneBlank("bob", "") = false
StringUtils.isNoneBlank(" bob ", null) = false
StringUtils.isNoneBlank(" ", "bar") = false
StringUtils.isNoneBlank("foo", "bar") = true
1
public static String trim(String str)

移除字符串两端的空字符串,制表符char <= 32如:\n \t
如果为空的话,返回空

如果为””

1
2
3
4
5
StringUtils.trim(null)          = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"

变体有

1
2
public static String trimToNull(String str)
public static String trimToEmpty(String str)

不常用,跟trim()方法类似

1
2
3
4
public static String strip(String str)

public static String strip(String str,
String stripChars)

str:被处理的字符串,可为空
stripChars: 删除的字符串,

1
2
3
4
5
6
7
StringUtils.strip(null, *)          = null
StringUtils.strip("", *) = ""
StringUtils.strip("abc", null) = "abc"
StringUtils.strip(" abc", null) = "abc"
StringUtils.strip("abc ", null) = "abc"
StringUtils.strip(" abc ", null) = "abc"
StringUtils.strip(" abcyx", "xyz") = " abc"
1
2
public static boolean equals(CharSequence cs1,
CharSequence cs2)

字符串比对方法,是比较实用的方法之一,两个比较的字符串都能为空,不会报空指针异常。

1
2
3
4
5
StringUtils.equals(null, null)   = true
StringUtils.equals(null, "abc") = false
StringUtils.equals("abc", null) = false
StringUtils.equals("abc", "abc") = true
StringUtils.equals("abc", "ABC") = false
1
2
public static boolean equalsIgnoreCase(CharSequence str1,
CharSequence str2)

上面方法的变体
字符串比较(忽略大小写),在验证码……等字符串比较,真是很实用。

1
2
3
4
5
StringUtils.equalsIgnoreCase(null, null)   = true
StringUtils.equalsIgnoreCase(null, "abc") = false
StringUtils.equalsIgnoreCase("abc", null) = false
StringUtils.equalsIgnoreCase("abc", "abc") = true
StringUtils.equalsIgnoreCase("abc", "ABC") = true
1
2
public static int indexOf(CharSequence seq,
int searchChar)

indexOf这个方法不必多说,这个方法主要处理掉了空字符串的问题,不会报空指针,有一定用处

1
2
3
4
StringUtils.indexOf(null, *)         = -1
StringUtils.indexOf("", *) = -1
StringUtils.indexOf("aabaabaa", 'a') = 0
StringUtils.indexOf("aabaabaa", 'b') = 2
1
2
3
public static int ordinalIndexOf(CharSequence str,
CharSequence searchStr,
int ordinal)

字符串在另外一个字符串里,出现第Ordinal次的位置

1
2
3
4
5
6
7
8
9
10
11
StringUtils.ordinalIndexOf(null, *, *)          = -1
StringUtils.ordinalIndexOf(*, null, *) = -1
StringUtils.ordinalIndexOf("", "", *) = 0
StringUtils.ordinalIndexOf("aabaabaa", "a", 1) = 0
StringUtils.ordinalIndexOf("aabaabaa", "a", 2) = 1
StringUtils.ordinalIndexOf("aabaabaa", "b", 1) = 2
StringUtils.ordinalIndexOf("aabaabaa", "b", 2) = 5
StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1
StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4
StringUtils.ordinalIndexOf("aabaabaa", "", 1) = 0
StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
1
2
public static int lastIndexOf(CharSequence seq,
int searchChar)

字符串最后一次出现的位置

1
2
3
4
StringUtils.lastIndexOf(null, *)         = -1
StringUtils.lastIndexOf("", *) = -1
StringUtils.lastIndexOf("aabaabaa", 'a') = 7
StringUtils.lastIndexOf("aabaabaa", 'b') = 5
1
2
3
public static int lastOrdinalIndexOf(CharSequence str,
CharSequence searchStr,
int ordinal)

字符串searchStr在str里面出现倒数第ordinal出现的位置

1
2
3
4
5
6
7
8
9
10
11
StringUtils.lastOrdinalIndexOf(null, *, *)          = -1
StringUtils.lastOrdinalIndexOf(*, null, *) = -1
StringUtils.lastOrdinalIndexOf("", "", *) = 0
StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 1) = 7
StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 2) = 6
StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 1) = 5
StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 2) = 2
StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 1) = 4
StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 2) = 1
StringUtils.lastOrdinalIndexOf("aabaabaa", "", 1) = 8
StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2) = 8
1
2
public static boolean contains(CharSequence seq,
int searchChar)

字符串seq是否包含searchChar

1
2
3
4
StringUtils.contains(null, *)    = false
StringUtils.contains("", *) = false
StringUtils.contains("abc", 'a') = true
StringUtils.contains("abc", 'z') = false
1
2
public static boolean containsAny(CharSequence cs,
char... searchChars)

包含后面数组中的任意对象,返回true

1
2
3
4
5
6
7
StringUtils.containsAny(null, *)                = false
StringUtils.containsAny("", *) = false
StringUtils.containsAny(*, null) = false
StringUtils.containsAny(*, []) = false
StringUtils.containsAny("zzabyycdxx",['z','a']) = true
StringUtils.containsAny("zzabyycdxx",['b','y']) = true
StringUtils.containsAny("aba", ['z']) = false
1
2
public static String substring(String str,
int start)

字符串截取

1
2
3
4
5
6
7
StringUtils.substring(null, *)   = null
StringUtils.substring("", *) = ""
StringUtils.substring("abc", 0) = "abc"
StringUtils.substring("abc", 2) = "c"
StringUtils.substring("abc", 4) = ""
StringUtils.substring("abc", -2) = "bc"
StringUtils.substring("abc", -4) = "abc"
1
2
3
4
5
6
7
public static String left(String str,
int len)
public static String right(String str,
int len)
public static String mid(String str,
int pos,
int len)

这三个方法类似都是截取字符串

1
2
public static String[] split(String str,
String separatorChars)

字符串分割

1
2
3
4
5
6
StringUtils.split(null, *)         = null
StringUtils.split("", *) = []
StringUtils.split("abc def", null) = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
1
public static <T> String join(T... elements)

字符串连接

1
2
3
4
5
StringUtils.join(null)            = null
StringUtils.join([]) = ""
StringUtils.join([null]) = ""
StringUtils.join(["a", "b", "c"]) = "abc"
StringUtils.join([null, "", "a"]) = "a"
1
2
public static String join(Object[] array,
char separator)

特定字符串连接数组,很多情况下还是蛮实用,不用自己取拼字符串

1
2
3
4
5
6
7
8
9
10
11
12
StringUtils.join(null, *)               = null
StringUtils.join([], *) = ""
StringUtils.join([null], *) = ""
StringUtils.join(["a", "b", "c"], ';') = "a;b;c"
StringUtils.join(["a", "b", "c"], null) = "abc"
StringUtils.join([null, "", "a"], ';') = ";;a"
public static String deleteWhitespace(String str)
删除空格
StringUtils.deleteWhitespace(null) = null
StringUtils.deleteWhitespace("") = ""
StringUtils.deleteWhitespace("abc") = "abc"
StringUtils.deleteWhitespace(" ab c ") = "abc"
1
2
public static String removeStart(String str,
String remove)

删除以特定字符串开头的字符串,如果没有的话,就不删除。

1
2
3
4
5
6
7
StringUtils.removeStart(null, *)      = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) = *
StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
StringUtils.removeStart("domain.com", "www.") = "domain.com"
StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStart("abc", "") = "abc"
1
2
3
public static String rightPad(String str,
int size,
char padChar)

生成订单号,的时候还是很实用的。右边自动补齐。

1
2
3
4
5
6
StringUtils.rightPad(null, *, *)     = null
StringUtils.rightPad("", 3, 'z') = "zzz"
StringUtils.rightPad("bat", 3, 'z') = "bat"
StringUtils.rightPad("bat", 5, 'z') = "batzz"
StringUtils.rightPad("bat", 1, 'z') = "bat"
StringUtils.rightPad("bat", -1, 'z') = "bat"
1
2
3
public static String leftPad(String str,
int size,
char padChar)

左边自动补齐

1
2
3
4
5
6
StringUtils.leftPad(null, *, *)     = null
StringUtils.leftPad("", 3, 'z') = "zzz"
StringUtils.leftPad("bat", 3, 'z') = "bat"
StringUtils.leftPad("bat", 5, 'z') = "zzbat"
StringUtils.leftPad("bat", 1, 'z') = "bat"
StringUtils.leftPad("bat", -1, 'z') = "bat"
1
2
public static String center(String str,
int size)

将字符在某特定长度下,句子

1
2
3
4
5
6
StringUtils.center(null, *)   = null
StringUtils.center("", 4) = " "
StringUtils.center("ab", -1) = "ab"
StringUtils.center("ab", 4) = " ab "
StringUtils.center("abcd", 2) = "abcd"
StringUtils.center("a", 4) = " a "
1
public static String capitalize(String str)

首字母大写

1
2
3
4
5
StringUtils.capitalize(null)  = null
StringUtils.capitalize("") = ""
StringUtils.capitalize("cat") = "Cat"
StringUtils.capitalize("cAt") = "CAt"
public static String swapCase(String str)

反向大小写

1
2
3
StringUtils.swapCase(null)                 = null
StringUtils.swapCase("") = ""
StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
1
public static boolean isAlpha(CharSequence cs)

判断字符串是否由字母组成

1
2
3
4
5
6
StringUtils.isAlpha(null)   = false
StringUtils.isAlpha("") = false
StringUtils.isAlpha(" ") = false
StringUtils.isAlpha("abc") = true
StringUtils.isAlpha("ab2c") = false
StringUtils.isAlpha("ab-c") = false
1
2
public static String defaultString(String str,
String defaultStr)

默认字符串,相当于三目运算,前面弱为空,则返回后面一个参数

1
2
3
StringUtils.defaultString(null, "NULL")  = "NULL"
StringUtils.defaultString("", "NULL") = ""
StringUtils.defaultString("bat", "NULL") = "bat"
1
public static String reverse(String str)

字符串翻转

1
2
3
StringUtils.reverse(null)  = null
StringUtils.reverse("") = ""
StringUtils.reverse("bat") = "tab"
1
2
public static String abbreviate(String str,
int maxWidth)

缩略字符串,
省略号要占三位。maxWith小于3位会报错。

1
2
3
4
5
6
7
StringUtils.abbreviate(null, *)      = null
StringUtils.abbreviate("", 4) = ""
StringUtils.abbreviate("abcdefg", 6) = "abc..."
StringUtils.abbreviate("abcdefg", 7) = "abcdefg"
StringUtils.abbreviate("abcdefg", 8) = "abcdefg"
StringUtils.abbreviate("abcdefg", 4) = "a..."
StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException
1
2
3
public static String abbreviate(String str,
int offset,
int maxWidth)

缩略字符串的一些高级用法

1
2
3
4
5
6
7
8
9
10
11
12
13
StringUtils.abbreviate(null, *, *)                = null
StringUtils.abbreviate("", 0, 4) = ""
StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..."
StringUtils.abbreviate("abcdefghijklmno", 0, 10) = "abcdefg..."
StringUtils.abbreviate("abcdefghijklmno", 1, 10) = "abcdefg..."
StringUtils.abbreviate("abcdefghijklmno", 4, 10) = "abcdefg..."
StringUtils.abbreviate("abcdefghijklmno", 5, 10) = "...fghi..."
StringUtils.abbreviate("abcdefghijklmno", 6, 10) = "...ghij..."
StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno"
StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno"
StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno"
StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException
StringUtils.abbreviate("abcdefghij", 5, 6) = IllegalArgumentException
1
2
public static String wrap(String str,
char wrapWith)

包装,用后面的字符串对前面的字符串进行包装

1
2
3
4
5
6
StringUtils.wrap(null, *)        = null
StringUtils.wrap("", *) = ""
StringUtils.wrap("ab", '\0') = "ab"
StringUtils.wrap("ab", 'x') = "xabx"
StringUtils.wrap("ab", '\'') = "'ab'"
StringUtils.wrap("\"ab\"", '\"') = "\"\"ab\"\""

5、Redis客户端Jedis

使用Jedis操作Redis

1
2
3
4
5
6
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->  
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>

测试案例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestRedis {
private Jedis jedis;

@Before
public void setup() {
//连接redis服务器,192.168.0.100:6379
jedis = new Jedis("192.168.0.100", 6379);
//权限认证
jedis.auth("admin");
}

/**
* redis存储字符串
*/
@Test
public void testString() {
//-----添加数据----------
jedis.set("name","xinxin");//向key-->name中放入了value-->xinxin
System.out.println(jedis.get("name"));//执行结果:xinxin

jedis.append("name", " is my lover"); //拼接
System.out.println(jedis.get("name"));

jedis.del("name"); //删除某个键
System.out.println(jedis.get("name"));
//设置多个键值对
jedis.mset("name","liuling","age","23","qq","476777XXX");
jedis.incr("age"); //进行加1操作
System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("qq"));

}

/**
* redis操作Map
*/
@Test
public void testMap() {
//-----添加数据----------
Map<String, String> map = new HashMap<String, String>();
map.put("name", "xinxin");
map.put("age", "22");
map.put("qq", "123456");
jedis.hmset("user",map);
//取出user中的name,执行结果:[minxr]-->注意结果是一个泛型的List
//第一个参数是存入redis中map对象的key,后面跟的是放入map中的对象的key,后面的key可以跟多个,是可变参数
List<String> rsmap = jedis.hmget("user", "name", "age", "qq");
System.out.println(rsmap);

//删除map中的某个键值
jedis.hdel("user","age");
System.out.println(jedis.hmget("user", "age")); //因为删除了,所以返回的是null
System.out.println(jedis.hlen("user")); //返回key为user的键中存放的值的个数2
System.out.println(jedis.exists("user"));//是否存在key为user的记录 返回true
System.out.println(jedis.hkeys("user"));//返回map对象中的所有key
System.out.println(jedis.hvals("user"));//返回map对象中的所有value

Iterator<String> iter=jedis.hkeys("user").iterator();
while (iter.hasNext()){
String key = iter.next();
System.out.println(key+":"+jedis.hmget("user",key));
}
}

/**
* jedis操作List
*/
@Test
public void testList(){
//开始前,先移除所有的内容
jedis.del("java framework");
System.out.println(jedis.lrange("java framework",0,-1));
//先向key java framework中存放三条数据
jedis.lpush("java framework","spring");
jedis.lpush("java framework","struts");
jedis.lpush("java framework","hibernate");
//再取出所有数据jedis.lrange是按范围取出,
// 第一个是key,第二个是起始位置,第三个是结束位置,jedis.llen获取长度 -1表示取得所有
System.out.println(jedis.lrange("java framework",0,-1));

jedis.del("java framework");
jedis.rpush("java framework","spring");
jedis.rpush("java framework","struts");
jedis.rpush("java framework","hibernate");
System.out.println(jedis.lrange("java framework",0,-1));
}

/**
* jedis操作Set
*/
@Test
public void testSet(){
//添加
jedis.sadd("user","liuling");
jedis.sadd("user","xinxin");
jedis.sadd("user","ling");
jedis.sadd("user","zhangxinxin");
jedis.sadd("user","who");
//移除noname
jedis.srem("user","who");
System.out.println(jedis.smembers("user"));//获取所有加入的value
System.out.println(jedis.sismember("user", "who"));//判断 who 是否是user集合的元素
System.out.println(jedis.srandmember("user"));
System.out.println(jedis.scard("user"));//返回集合的元素个数
}

@Test
public void test() throws InterruptedException {
//jedis 排序
//注意,此处的rpush和lpush是List的操作。是一个双向链表(但从表现来看的)
jedis.del("a");//先清除数据,再加入数据进行测试
jedis.rpush("a", "1");
jedis.lpush("a","6");
jedis.lpush("a","3");
jedis.lpush("a","9");
System.out.println(jedis.lrange("a",0,-1));// [9, 3, 6, 1]
System.out.println(jedis.sort("a")); //[1, 3, 6, 9] //输入排序后结果
System.out.println(jedis.lrange("a",0,-1));
}

@Test
public void testRedisPool() {
RedisUtil.getJedis().set("newname", "中文测试");
System.out.println(RedisUtil.getJedis().get("newname"));
}
}

Redis连接池

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public final class RedisUtil {

//Redis服务器IP
private static String ADDR = "192.168.0.100";

//Redis的端口号
private static int PORT = 6379;

//访问密码
private static String AUTH = "admin";

//可用连接实例的最大数目,默认值为8;
//如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
private static int MAX_ACTIVE = 1024;

//控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值也是8。
private static int MAX_IDLE = 200;

//等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException;
private static int MAX_WAIT = 10000;

private static int TIMEOUT = 10000;

//在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
private static boolean TEST_ON_BORROW = true;

private static JedisPool jedisPool = null;

/**
* 初始化Redis连接池
*/
static {
try {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(MAX_ACTIVE);
config.setMaxIdle(MAX_IDLE);
config.setMaxWait(MAX_WAIT);
config.setTestOnBorrow(TEST_ON_BORROW);
jedisPool = new JedisPool(config, ADDR, PORT, TIMEOUT, AUTH);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 获取Jedis实例
* @return
*/
public synchronized static Jedis getJedis() {
try {
if (jedisPool != null) {
Jedis resource = jedisPool.getResource();
return resource;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
* 释放jedis资源
* @param jedis
*/
public static void returnResource(final Jedis jedis) {
if (jedis != null) {
jedisPool.returnResource(jedis);
}
}
}

6、IE8下js不执行,在开发者模式下 点击“启动调试”按钮后才执行,怎么解决?

删除测试代码。ie8非开发模式下无法用console对象。

7、腾讯云CDN使用

https://blog.csdn.net/Lunaqi/article/details/78987936

I Don't Want Your Money, I Want Aragaki Yui.