斗地主中显示swift error协议没有转换jee的协议是咋回事

我的手机上有JAVA,下载上了QQ斗地主,但是登陆的时候却总是提示网络连接错误,这是怎么回事?_百度知道
我的手机上有JAVA,下载上了QQ斗地主,但是登陆的时候却总是提示网络连接错误,这是怎么回事?
在网上搜了一圈也没看到有个真正懂行的,希望得到详细的解决方案,谢谢
详细答案啊详细答案,拜托大家,说清楚点
我有更好的答案
呵呵,这很简单,有可能是你CDMA网络或是哪个连接没开好,我以前就是这样。
那我应该设置网络还是设置JAVA啊?
采纳率:6%
可能需要设置应用程序的权限,让它有使用网络连接的权限。
我那个JAVA的安全性设置里有个本地网络连接,上面只有一个选择就是不连接,这样是不是不行啊
到qq斗地主那里选项里设置下就好了
为您推荐:
其他类似问题
您可能关注的内容
qq斗地主的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。/ jee-site
项目语言:None
权限:read-only(如需更高权限请先加入项目)
Index: Reflections.java
===================================================================
--- Reflections.java (revision 0)
+++ Reflections.java (revision 2)
@@ -0,0 +1,304 @@
+ * Copyright (c)
springside.org.cn
+package com.thinkgem.jeesite.common.
+import java.lang.reflect.F
+import java.lang.reflect.InvocationTargetE
+import java.lang.reflect.M
+import java.lang.reflect.M
+import java.lang.reflect.ParameterizedT
+import java.lang.reflect.T
+import org.apache.commons.lang3.StringU
+import org.apache.commons.lang3.V
+import org.slf4j.L
+import org.slf4j.LoggerF
+import org.springframework.util.A
+ * 反射工具类.
+ * 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数.
+ * @author calvin
+ * @version
+@SuppressWarnings(&rawtypes&)
+public class Reflections {
+ private static final String SETTER_PREFIX = &set&;
+ private static final String GETTER_PREFIX = &get&;
+ private static final String CGLIB_CLASS_SEPARATOR = &$$&;
+ private static Logger logger = LoggerFactory.getLogger(Reflections.class);
* 调用Getter方法.
* 支持多级,如:对象名.对象名.方法
+ public static Object invokeGetter(Object obj, String propertyName) {
Object object =
for (String name : StringUtils.split(propertyName, &.&)){
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
* 调用Setter方法, 仅匹配方法名。
* 支持多级,如:对象名.对象名.方法
+ public static void invokeSetter(Object obj, String propertyName, Object value) {
Object object =
String[] names = StringUtils.split(propertyName, &.&);
for (int i=0; i&names. i++){
if(i&names.length-1){
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]);
invokeMethodByName(object, setterMethodName, new Object[] { value });
* 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
+ public static Object getFieldValue(final Object obj, final String fieldName) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
throw new IllegalArgumentException(&Could not find field [& + fieldName + &] on target [& + obj + &]&);
Object result =
result = field.get(obj);
} catch (IllegalAccessException e) {
logger.error(&不可能抛出的异常{}&, e.getMessage());
* 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
+ public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
throw new IllegalArgumentException(&Could not find field [& + fieldName + &] on target [& + obj + &]&);
field.set(obj, value);
} catch (IllegalAccessException e) {
logger.error(&不可能抛出的异常:{}&, e.getMessage());
* 直接调用对象方法, 无视private/protected修饰符.
* 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用.
* 同时匹配方法名+参数类型,
+ public static Object invokeMethod(final Object obj, final String methodName, final Class&?&[] parameterTypes,
final Object[] args) {
Method method = getAccessibleMethod(obj, methodName, parameterTypes);
if (method == null) {
throw new IllegalArgumentException(&Could not find method [& + methodName + &] on target [& + obj + &]&);
return method.invoke(obj, args);
} catch (Exception e) {
throw convertReflectionExceptionToUnchecked(e);
* 直接调用对象方法, 无视private/protected修饰符,
* 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
* 只匹配函数名,如果有多个同名函数调用第一个。
+ public static Object invokeMethodByName(final Object obj, final String methodName, final Object[] args) {
Method method = getAccessibleMethodByName(obj, methodName);
if (method == null) {
throw new IllegalArgumentException(&Could not find method [& + methodName + &] on target [& + obj + &]&);
return method.invoke(obj, args);
} catch (Exception e) {
throw convertReflectionExceptionToUnchecked(e);
* 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
+ public static Field getAccessibleField(final Object obj, final String fieldName) {
Validate.notNull(obj, &object can't be null&);
Validate.notBlank(fieldName, &fieldName can't be blank&);
for (Class&?& superClass = obj.getClass(); superClass != Object. superClass = superClass.getSuperclass()) {
Field field = superClass.getDeclaredField(fieldName);
makeAccessible(field);
} catch (NoSuchFieldException e) {//NOSONAR
// Field不在当前类定义,继续向上转型
// new add
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 匹配函数名+参数类型。
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
+ public static Method getAccessibleMethod(final Object obj, final String methodName,
final Class&?&... parameterTypes) {
Validate.notNull(obj, &object can't be null&);
Validate.notBlank(methodName, &methodName can't be blank&);
for (Class&?& searchType = obj.getClass(); searchType != Object. searchType = searchType.getSuperclass()) {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method);
} catch (NoSuchMethodException e) {
// Method不在当前类定义,继续向上转型
// new add
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 只匹配函数名。
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
+ public static Method getAccessibleMethodByName(final Object obj, final String methodName) {
Validate.notNull(obj, &object can't be null&);
Validate.notBlank(methodName, &methodName can't be blank&);
for (Class&?& searchType = obj.getClass(); searchType != Object. searchType = searchType.getSuperclass()) {
Method[] methods = searchType.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals(methodName)) {
makeAccessible(method);
* 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
+ public static void makeAccessible(Method method) {
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
&& !method.isAccessible()) {
method.setAccessible(true);
* 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。
+ public static void makeAccessible(Field field) {
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier
.isFinal(field.getModifiers())) && !field.isAccessible()) {
field.setAccessible(true);
* 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处
* 如无法找到, 返回Object.class.
* public UserDao extends HibernateDao&User&
* @param clazz The class to introspect
* @return the first generic declaration, or Object.class if cannot be determined
+ @SuppressWarnings(&unchecked&)
+ public static &T& Class&T& getClassGenricType(final Class clazz) {
return getClassGenricType(clazz, 0);
* 通过反射, 获得Class定义中声明的父类的泛型参数的类型.
* 如无法找到, 返回Object.class.
* 如public UserDao extends HibernateDao&User,Long&
* @param clazz clazz The class to introspect
* @param index the Index of the generic ddeclaration,start from 0.
* @return the index generic declaration, or Object.class if cannot be determined
+ public static Class getClassGenricType(final Class clazz, final int index) {
Type genType = clazz.getGenericSuperclass();
if (!(genType instanceof ParameterizedType)) {
logger.warn(clazz.getSimpleName() + &'s superclass not ParameterizedType&);
return Object.
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
if (index &= params.length || index & 0) {
logger.warn(&Index: & + index + &, Size of & + clazz.getSimpleName() + &'s Parameterized Type: &
+ params.length);
return Object.
if (!(params[index] instanceof Class)) {
logger.warn(clazz.getSimpleName() + & not set the actual class on superclass generic parameter&);
return Object.
return (Class) params[index];
+ public static Class&?& getUserClass(Object instance) {
Assert.notNull(instance, &Instance must not be null&);
Class clazz = instance.getClass();
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
Class&?& superClass = clazz.getSuperclass();
if (superClass != null && !Object.class.equals(superClass)) {
return superC
* 将反射时的checked exception转换为unchecked exception.
+ public static RuntimeException convertReflectionExceptionToUnchecked(Exception e) {
if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException
|| e instanceof NoSuchMethodException) {
return new IllegalArgumentException(e);
} else if (e instanceof InvocationTargetException) {
return new RuntimeException(((InvocationTargetException) e).getTargetException());
} else if (e instanceof RuntimeException) {
return (RuntimeException)
return new RuntimeException(&Unexpected Checked Exception.&, e);
Index: TimeUtils.java
===================================================================
--- TimeUtils.java (revision 0)
+++ TimeUtils.java (revision 2)
@@ -0,0 +1,324 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.
+import java.util.A
+import java.util.D
+import org.apache.commons.lang3.time.DateFormatU
+ * 时间计算工具类
+ * @author ThinkGem
+ * @version
+public class TimeUtils {
+ public static String toTimeString(long time) {
TimeUtils t = new TimeUtils(time);
int day = t.get(TimeUtils.DAY);
int hour = t.get(TimeUtils.HOUR);
int minute = t.get(TimeUtils.MINUTE);
int second = t.get(TimeUtils.SECOND);
StringBuilder sb = new StringBuilder();
if (day & 0){
sb.append(day).append(&天&);
if (hour & 0){
sb.append(hour).append(&时&);
if (minute & 0){
sb.append(minute).append(&分&);
if (second & 0){
sb.append(second).append(&秒&);
return sb.toString();
* 时间字段常量,表示“秒”
public final static int SECOND = 0;
* 时间字段常量,表示“分”
public final static int MINUTE = 1;
* 时间字段常量,表示“时”
public final static int HOUR = 2;
* 时间字段常量,表示“天”
public final static int DAY = 3;
* 各常量允许的最大值
private final int[] maxFields = { 59, 59, 23, Integer.MAX_VALUE - 1 };
* 各常量允许的最小值
private final int[] minFields = { 0, 0, 0, Integer.MIN_VALUE };
* 默认的字符串格式时间分隔符
private String timeSeparator = &:&;
* 时间数据容器
private int[] fields = new int[4];
* 无参构造,将各字段置为 0
public TimeUtils() {
this(0, 0, 0, 0);
* 使用时、分构造一个时间
* @param hour
* @param minute
public TimeUtils(int hour, int minute) {
this(0, hour, minute, 0);
* 使用时、分、秒构造一个时间
* @param hour
* @param minute
* @param second
public TimeUtils(int hour, int minute, int second) {
this(0, hour, minute, second);
* 使用一个字符串构造时间&br/&
* Time time = new Time(&14:22:23&);
* @param time
字符串格式的时间,默认采用“:”作为分隔符
public TimeUtils(String time) {
this(time, null);
System.out.println(time);
* 使用时间毫秒构建时间
* @param time
public TimeUtils(long time){
this(new Date(time));
* 使用日期对象构造时间
* @param date
public TimeUtils(Date date){
this(DateFormatUtils.formatUTC(date, &HH:mm:ss&));
* 使用天、时、分、秒构造时间,进行全字符的构造
* @param day
* @param hour
* @param minute
* @param second
public TimeUtils(int day, int hour, int minute, int second) {
initialize(day, hour, minute, second);
* 使用一个字符串构造时间,指定分隔符&br/&
* Time time = new Time(&14-22-23&, &-&);
* @param time
字符串格式的时间
public TimeUtils(String time, String timeSeparator) {
if(timeSeparator != null) {
setTimeSeparator(timeSeparator);
parseTime(time);
* 设置时间字段的值
* @param field
时间字段常量
* @param value
时间字段的值
public void set(int field, int value) {
if(value & minFields[field]) {
throw new IllegalArgumentException(value + &, time value must be positive.&);
fields[field] = value % (maxFields[field] + 1);
// 进行进位计算
int carry = value / (maxFields[field] + 1);
if(carry & 0) {
int upFieldValue = get(field + 1);
set(field + 1, upFieldValue + carry);
* 获得时间字段的值
* @param field
时间字段常量
该时间字段的值
public int get(int field) {
if(field & 0 || field & fields.length - 1) {
throw new IllegalArgumentException(field + &, field value is error.&);
return fields[field];
* 将时间进行“加”运算,即加上一个时间
* @param time
需要加的时间
运算后的时间
public TimeUtils addTime(TimeUtils time) {
TimeUtils result = new TimeUtils();
int up = 0;
// 进位标志
for (int i = 0; i & fields. i++) {
int sum = fields[i] + time.fields[i] +
up = sum / (maxFields[i] + 1);
result.fields[i] = sum % (maxFields[i] + 1);
* 将时间进行“减”运算,即减去一个时间
* @param time
需要减的时间
运算后的时间
public TimeUtils subtractTime(TimeUtils time) {
TimeUtils result = new TimeUtils();
int down = 0;
// 退位标志
for (int i = 0, k = fields.length - 1; i & i++) {
int difference = fields[i] +
if (difference &= time.fields[i]) {
difference -= time.fields[i];
difference += maxFields[i] + 1 - time.fields[i];
down = -1;
result.fields[i] =
result.fields[DAY] = fields[DAY] - time.fields[DAY] +
* 获得时间字段的分隔符
public String getTimeSeparator() {
return timeS
* 设置时间字段的分隔符(用于字符串格式的时间)
* @param timeSeparator
分隔符字符串
public void setTimeSeparator(String timeSeparator) {
this.timeSeparator = timeS
private void initialize(int day, int hour, int minute, int second) {
set(DAY, day);
set(HOUR, hour);
set(MINUTE, minute);
set(SECOND, second);
private void parseTime(String time) {
if(time == null) {
initialize(0, 0, 0, 0);
String t =
int field = DAY;
set(field--, 0);
int p = -1;
while((p = t.indexOf(timeSeparator)) & -1) {
parseTimeField(time, t.substring(0, p), field--);
t = t.substring(p + timeSeparator.length());
parseTimeField(time, t, field--);
private void parseTimeField(String time, String t, int field) {
if(field & SECOND || t.length() & 1) {
parseTimeException(time);
char[] chs = t.toCharArray();
int n = 0;
for(int i = 0; i & chs. i++) {
if(chs[i] &= ' ') {
if(chs[i] &= '0' && chs[i] &= '9') {
n = n * 10 + chs[i] - '0';
parseTimeException(time);
set(field, n);
private void parseTimeException(String time) {
throw new IllegalArgumentException(time + &, time format error, HH&
+ this.timeSeparator + &mm& + this.timeSeparator + &ss&);
public String toString() {
StringBuilder sb = new StringBuilder(16);
sb.append(fields[DAY]).append(',').append(' ');
buildString(sb, HOUR).append(timeSeparator);
buildString(sb, MINUTE).append(timeSeparator);
buildString(sb, SECOND);
return sb.toString();
private StringBuilder buildString(StringBuilder sb, int field) {
if(fields[field] & 10) {
sb.append('0');
return sb.append(fields[field]);
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + Arrays.hashCode(fields);
public boolean equals(Object obj) {
if (this == obj)
if (obj == null)
if (getClass() != obj.getClass())
final TimeUtils other = (TimeUtils)
if (!Arrays.equals(fields, other.fields)) {
\ No newline at end of file
Index: JedisUtils.java
===================================================================
--- JedisUtils.java (revision 0)
+++ JedisUtils.java (revision 2)
@@ -0,0 +1,836 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.
+import java.util.L
+import java.util.M
+import java.util.S
+import org.slf4j.L
+import org.slf4j.LoggerF
+import com.google.common.collect.L
+import com.google.common.collect.M
+import com.google.common.collect.S
+import com.thinkgem.jeesite.common.config.G
+import redis.clients.jedis.J
+import redis.clients.jedis.JedisP
+import redis.clients.jedis.exceptions.JedisE
+ * Jedis Cache 工具类
+ * @author ThinkGem
+ * @version
+public class JedisUtils {
+ private static Logger logger = LoggerFactory.getLogger(JedisUtils.class);
+ private static JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class);
+ public static final String KEY_PREFIX = Global.getConfig(&redis.keyPrefix&);
* 获取缓存
* @param key 键
* @return 值
+ public static String get(String key) {
String value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.get(key);
value = StringUtils.isNotBlank(value) && !&nil&.equalsIgnoreCase(value) ? value :
logger.debug(&get {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&get {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取缓存
* @param key 键
* @return 值
+ public static Object getObject(String key) {
Object value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
value = toObject(jedis.get(getBytesKey(key)));
logger.debug(&getObject {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getObject {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static String set(String key, String value, int cacheSeconds) {
String result =
Jedis jedis =
jedis = getResource();
result = jedis.set(key, value);
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&set {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&set {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static String setObject(String key, Object value, int cacheSeconds) {
String result =
Jedis jedis =
jedis = getResource();
result = jedis.set(getBytesKey(key), toBytes(value));
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setObject {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setObject {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取List缓存
* @param key 键
* @return 值
+ public static List&String& getList(String key) {
List&String& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.lrange(key, 0, -1);
logger.debug(&getList {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getList {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取List缓存
* @param key 键
* @return 值
+ public static List&Object& getObjectList(String key) {
List&Object& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
List&byte[]& list = jedis.lrange(getBytesKey(key), 0, -1);
value = Lists.newArrayList();
for (byte[] bs : list){
value.add(toObject(bs));
logger.debug(&getObjectList {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getObjectList {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置List缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static long setList(String key, List&String& value, int cacheSeconds) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
result = jedis.rpush(key, (String[])value.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setList {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setList {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置List缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static long setObjectList(String key, List&Object& value, int cacheSeconds) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
List&byte[]& list = Lists.newArrayList();
for (Object o : value){
list.add(toBytes(o));
result = jedis.rpush(getBytesKey(key), (byte[][])list.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setObjectList {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setObjectList {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向List缓存中添加值
* @param key 键
* @param value 值
+ public static long listAdd(String key, String... value) {
long result = 0;
Jedis jedis =
jedis = getResource();
result = jedis.rpush(key, value);
logger.debug(&listAdd {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&listAdd {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向List缓存中添加值
* @param key 键
* @param value 值
+ public static long listObjectAdd(String key, Object... value) {
long result = 0;
Jedis jedis =
jedis = getResource();
List&byte[]& list = Lists.newArrayList();
for (Object o : value){
list.add(toBytes(o));
result = jedis.rpush(getBytesKey(key), (byte[][])list.toArray());
logger.debug(&listObjectAdd {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&listObjectAdd {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取缓存
* @param key 键
* @return 值
+ public static Set&String& getSet(String key) {
Set&String& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.smembers(key);
logger.debug(&getSet {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getSet {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取缓存
* @param key 键
* @return 值
+ public static Set&Object& getObjectSet(String key) {
Set&Object& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
value = Sets.newHashSet();
Set&byte[]& set = jedis.smembers(getBytesKey(key));
for (byte[] bs : set){
value.add(toObject(bs));
logger.debug(&getObjectSet {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getObjectSet {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置Set缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static long setSet(String key, Set&String& value, int cacheSeconds) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
result = jedis.sadd(key, (String[])value.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setSet {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setSet {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置Set缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static long setObjectSet(String key, Set&Object& value, int cacheSeconds) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
Set&byte[]& set = Sets.newHashSet();
for (Object o : value){
set.add(toBytes(o));
result = jedis.sadd(getBytesKey(key), (byte[][])set.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setObjectSet {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setObjectSet {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向Set缓存中添加值
* @param key 键
* @param value 值
+ public static long setSetAdd(String key, String... value) {
long result = 0;
Jedis jedis =
jedis = getResource();
result = jedis.sadd(key, value);
logger.debug(&setSetAdd {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setSetAdd {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向Set缓存中添加值
* @param key 键
* @param value 值
+ public static long setSetObjectAdd(String key, Object... value) {
long result = 0;
Jedis jedis =
jedis = getResource();
Set&byte[]& set = Sets.newHashSet();
for (Object o : value){
set.add(toBytes(o));
result = jedis.rpush(getBytesKey(key), (byte[][])set.toArray());
logger.debug(&setSetObjectAdd {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setSetObjectAdd {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取Map缓存
* @param key 键
* @return 值
+ public static Map&String, String& getMap(String key) {
Map&String, String& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.hgetAll(key);
logger.debug(&getMap {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getMap {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 获取Map缓存
* @param key 键
* @return 值
+ public static Map&String, Object& getObjectMap(String key) {
Map&String, Object& value =
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
value = Maps.newHashMap();
Map&byte[], byte[]& map = jedis.hgetAll(getBytesKey(key));
for (Map.Entry&byte[], byte[]& e : map.entrySet()){
value.put(StringUtils.toString(e.getKey()), toObject(e.getValue()));
logger.debug(&getObjectMap {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&getObjectMap {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置Map缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static String setMap(String key, Map&String, String& value, int cacheSeconds) {
String result =
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
result = jedis.hmset(key, value);
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setMap {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setMap {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 设置Map缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
+ public static String setObjectMap(String key, Map&String, Object& value, int cacheSeconds) {
String result =
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
Map&byte[], byte[]& map = Maps.newHashMap();
for (Map.Entry&String, Object& e : value.entrySet()){
map.put(getBytesKey(e.getKey()), toBytes(e.getValue()));
result = jedis.hmset(getBytesKey(key), (Map&byte[], byte[]&)map);
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
logger.debug(&setObjectMap {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&setObjectMap {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向Map缓存中添加值
* @param key 键
* @param value 值
+ public static String mapPut(String key, Map&String, String& value) {
String result =
Jedis jedis =
jedis = getResource();
result = jedis.hmset(key, value);
logger.debug(&mapPut {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&mapPut {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 向Map缓存中添加值
* @param key 键
* @param value 值
+ public static String mapObjectPut(String key, Map&String, Object& value) {
String result =
Jedis jedis =
jedis = getResource();
Map&byte[], byte[]& map = Maps.newHashMap();
for (Map.Entry&String, Object& e : value.entrySet()){
map.put(getBytesKey(e.getKey()), toBytes(e.getValue()));
result = jedis.hmset(getBytesKey(key), (Map&byte[], byte[]&)map);
logger.debug(&mapObjectPut {} = {}&, key, value);
} catch (Exception e) {
logger.warn(&mapObjectPut {} = {}&, key, value, e);
} finally {
returnResource(jedis);
* 移除Map缓存中的值
* @param key 键
* @param value 值
+ public static long mapRemove(String key, String mapKey) {
long result = 0;
Jedis jedis =
jedis = getResource();
result = jedis.hdel(key, mapKey);
logger.debug(&mapRemove {}
{}&, key, mapKey);
} catch (Exception e) {
logger.warn(&mapRemove {}
{}&, key, mapKey, e);
} finally {
returnResource(jedis);
* 移除Map缓存中的值
* @param key 键
* @param value 值
+ public static long mapObjectRemove(String key, String mapKey) {
long result = 0;
Jedis jedis =
jedis = getResource();
result = jedis.hdel(getBytesKey(key), getBytesKey(mapKey));
logger.debug(&mapObjectRemove {}
{}&, key, mapKey);
} catch (Exception e) {
logger.warn(&mapObjectRemove {}
{}&, key, mapKey, e);
} finally {
returnResource(jedis);
* 判断Map缓存中的Key是否存在
* @param key 键
* @param value 值
+ public static boolean mapExists(String key, String mapKey) {
boolean result =
Jedis jedis =
jedis = getResource();
result = jedis.hexists(key, mapKey);
logger.debug(&mapExists {}
{}&, key, mapKey);
} catch (Exception e) {
logger.warn(&mapExists {}
{}&, key, mapKey, e);
} finally {
returnResource(jedis);
* 判断Map缓存中的Key是否存在
* @param key 键
* @param value 值
+ public static boolean mapObjectExists(String key, String mapKey) {
boolean result =
Jedis jedis =
jedis = getResource();
result = jedis.hexists(getBytesKey(key), getBytesKey(mapKey));
logger.debug(&mapObjectExists {}
{}&, key, mapKey);
} catch (Exception e) {
logger.warn(&mapObjectExists {}
{}&, key, mapKey, e);
} finally {
returnResource(jedis);
* 删除缓存
* @param key 键
+ public static long del(String key) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(key)){
result = jedis.del(key);
logger.debug(&del {}&, key);
logger.debug(&del {} not exists&, key);
} catch (Exception e) {
logger.warn(&del {}&, key, e);
} finally {
returnResource(jedis);
* 删除缓存
* @param key 键
+ public static long delObject(String key) {
long result = 0;
Jedis jedis =
jedis = getResource();
if (jedis.exists(getBytesKey(key))){
result = jedis.del(getBytesKey(key));
logger.debug(&delObject {}&, key);
logger.debug(&delObject {} not exists&, key);
} catch (Exception e) {
logger.warn(&delObject {}&, key, e);
} finally {
returnResource(jedis);
* 缓存是否存在
* @param key 键
+ public static boolean exists(String key) {
boolean result =
Jedis jedis =
jedis = getResource();
result = jedis.exists(key);
logger.debug(&exists {}&, key);
} catch (Exception e) {
logger.warn(&exists {}&, key, e);
} finally {
returnResource(jedis);
* 缓存是否存在
* @param key 键
+ public static boolean existsObject(String key) {
boolean result =
Jedis jedis =
jedis = getResource();
result = jedis.exists(getBytesKey(key));
logger.debug(&existsObject {}&, key);
} catch (Exception e) {
logger.warn(&existsObject {}&, key, e);
} finally {
returnResource(jedis);
* 获取资源
* @throws JedisException
+ public static Jedis getResource() throws JedisException {
Jedis jedis =
jedis = jedisPool.getResource();
logger.debug(&getResource.&, jedis);
} catch (JedisException e) {
logger.warn(&getResource.&, e);
returnBrokenResource(jedis);
* 归还资源
* @param jedis
* @param isBroken
+ public static void returnBrokenResource(Jedis jedis) {
if (jedis != null) {
jedisPool.returnBrokenResource(jedis);
* 释放资源
* @param jedis
* @param isBroken
+ public static void returnResource(Jedis jedis) {
if (jedis != null) {
jedisPool.returnResource(jedis);
* 获取byte[]类型Key
* @param key
+ public static byte[] getBytesKey(Object object){
if(object instanceof String){
return StringUtils.getBytes((String)object);
return ObjectUtils.serialize(object);
* Object转换byte[]类型
* @param key
+ public static byte[] toBytes(Object object){
return ObjectUtils.serialize(object);
* byte[]型转换Object
* @param key
+ public static Object toObject(byte[] bytes){
return ObjectUtils.unserialize(bytes);
Index: excel/ExportExcel.java
===================================================================
--- excel/ExportExcel.java (revision 0)
+++ excel/ExportExcel.java (revision 2)
@@ -0,0 +1,477 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.
+import java.io.FileNotFoundE
+import java.io.FileOutputS
+import java.io.IOE
+import java.io.OutputS
+import java.lang.reflect.F
+import java.lang.reflect.M
+import java.util.C
+import java.util.C
+import java.util.D
+import java.util.HashM
+import java.util.L
+import java.util.M
+import javax.servlet.http.HttpServletR
+import org.apache.commons.lang3.StringU
+import org.apache.poi.ss.usermodel.C
+import org.apache.poi.ss.usermodel.CellS
+import org.apache.poi.ss.usermodel.C
+import org.apache.poi.ss.usermodel.DataF
+import org.apache.poi.ss.usermodel.F
+import org.apache.poi.ss.usermodel.IndexedC
+import org.apache.poi.ss.usermodel.R
+import org.apache.poi.ss.usermodel.S
+import org.apache.poi.ss.usermodel.W
+import org.apache.poi.ss.util.CellRangeA
+import org.apache.poi.xssf.streaming.SXSSFW
+import org.apache.poi.xssf.usermodel.XSSFClientA
+import org.apache.poi.xssf.usermodel.XSSFRichTextS
+import org.slf4j.L
+import org.slf4j.LoggerF
+import com.google.common.collect.L
+import com.thinkgem.jeesite.common.utils.E
+import com.thinkgem.jeesite.common.utils.R
+import com.thinkgem.jeesite.common.utils.excel.annotation.ExcelF
+import com.thinkgem.jeesite.modules.sys.utils.DictU
+ * 导出Excel文件(导出“XLSX”格式,支持大数据量导出
@see org.apache.poi.ss.SpreadsheetVersion)
+ * @author ThinkGem
+ * @version
+public class ExportExcel {
+ private static Logger log = LoggerFactory.getLogger(ExportExcel.class);
* 工作薄对象
+ private SXSSFW
* 工作表对象
+ private S
* 样式列表
+ private Map&String, CellStyle&
* 当前行号
* 注解列表(Object[]{ ExcelField, Field/Method })
+ List&Object[]& annotationList = Lists.newArrayList();
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
* @param cls 实体对象,通过annotation.ExportField获取标题
+ public ExportExcel(String title, Class&?& cls){
this(title, cls, 1);
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
* @param cls 实体对象,通过annotation.ExportField获取标题
* @param type 导出类型(1:导出数据;2:导出模板)
* @param groups 导入分组
+ public ExportExcel(String title, Class&?& cls, int type, int... groups){
// Get annotation field
Field[] fs = cls.getDeclaredFields();
for (Field f : fs){
ExcelField ef = f.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==type)){
if (groups!=null && groups.length&0){
boolean inGroup =
for (int g : groups){
if (inGroup){
for (int efg : ef.groups()){
if (g == efg){
annotationList.add(new Object[]{ef, f});
annotationList.add(new Object[]{ef, f});
// Get annotation method
Method[] ms = cls.getDeclaredMethods();
for (Method m : ms){
ExcelField ef = m.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==type)){
if (groups!=null && groups.length&0){
boolean inGroup =
for (int g : groups){
if (inGroup){
for (int efg : ef.groups()){
if (g == efg){
annotationList.add(new Object[]{ef, m});
annotationList.add(new Object[]{ef, m});
// Field sorting
Collections.sort(annotationList, new Comparator&Object[]&() {
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
// Initialize
List&String& headerList = Lists.newArrayList();
for (Object[] os : annotationList){
String t = ((ExcelField)os[0]).title();
// 如果是导出,则去掉注释
if (type==1){
String[] ss = StringUtils.split(t, &**&, 2);
if (ss.length==2){
t = ss[0];
headerList.add(t);
initialize(title, headerList);
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
* @param headers 表头数组
+ public ExportExcel(String title, String[] headers) {
initialize(title, Lists.newArrayList(headers));
* 构造函数
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
+ public ExportExcel(String title, List&String& headerList) {
initialize(title, headerList);
* 初始化函数
* @param title 表格标题,传“空值”,表示无标题
* @param headerList 表头列表
+ private void initialize(String title, List&String& headerList) {
this.wb = new SXSSFWorkbook(500);
this.sheet = wb.createSheet(&Export&);
this.styles = createStyles(wb);
// Create title
if (StringUtils.isNotBlank(title)){
Row titleRow = sheet.createRow(rownum++);
titleRow.setHeightInPoints(30);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellStyle(styles.get(&title&));
titleCell.setCellValue(title);
sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(),
titleRow.getRowNum(), titleRow.getRowNum(), headerList.size()-1));
// Create header
if (headerList == null){
throw new RuntimeException(&headerList not null!&);
Row headerRow = sheet.createRow(rownum++);
headerRow.setHeightInPoints(16);
for (int i = 0; i & headerList.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellStyle(styles.get(&header&));
String[] ss = StringUtils.split(headerList.get(i), &**&, 2);
if (ss.length==2){
cell.setCellValue(ss[0]);
Comment comment = this.sheet.createDrawingPatriarch().createCellComment(
new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
comment.setString(new XSSFRichTextString(ss[1]));
cell.setCellComment(comment);
cell.setCellValue(headerList.get(i));
sheet.autoSizeColumn(i);
for (int i = 0; i & headerList.size(); i++) {
int colWidth = sheet.getColumnWidth(i)*2;
sheet.setColumnWidth(i, colWidth & 3000 ? 3000 : colWidth);
log.debug(&Initialize success.&);
* 创建表格样式
* @param wb 工作薄对象
* @return 样式列表
+ private Map&String, CellStyle& createStyles(Workbook wb) {
Map&String, CellStyle& styles = new HashMap&String, CellStyle&();
CellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
Font titleFont = wb.createFont();
titleFont.setFontName(&Arial&);
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(titleFont);
styles.put(&title&, style);
style = wb.createCellStyle();
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
dataFont.setFontName(&Arial&);
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put(&data&, style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get(&data&));
style.setAlignment(CellStyle.ALIGN_LEFT);
styles.put(&data1&, style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get(&data&));
style.setAlignment(CellStyle.ALIGN_CENTER);
styles.put(&data2&, style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get(&data&));
style.setAlignment(CellStyle.ALIGN_RIGHT);
styles.put(&data3&, style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get(&data&));
style.setWrapText(true);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
headerFont.setFontName(&Arial&);
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put(&header&, style);
* 添加一行
* @return 行对象
+ public Row addRow(){
return sheet.createRow(rownum++);
* 添加一个单元格
* @param row 添加的行
* @param column 添加列号
* @param val 添加值
* @return 单元格对象
+ public Cell addCell(Row row, int column, Object val){
return this.addCell(row, column, val, 0, Class.class);
* 添加一个单元格
* @param row 添加的行
* @param column 添加列号
* @param val 添加值
* @param align 对齐方式(1:靠左;2:居中;3:靠右)
* @return 单元格对象
+ public Cell addCell(Row row, int column, Object val, int align, Class&?& fieldType){
Cell cell = row.createCell(column);
CellStyle style = styles.get(&data&+(align&=1&&align&=3?align:&&));
if (val == null){
cell.setCellValue(&&);
} else if (val instanceof String) {
cell.setCellValue((String) val);
} else if (val instanceof Integer) {
cell.setCellValue((Integer) val);
} else if (val instanceof Long) {
cell.setCellValue((Long) val);
} else if (val instanceof Double) {
cell.setCellValue((Double) val);
} else if (val instanceof Float) {
cell.setCellValue((Float) val);
} else if (val instanceof Date) {
DataFormat format = wb.createDataFormat();
style.setDataFormat(format.getFormat(&yyyy-MM-dd&));
cell.setCellValue((Date) val);
if (fieldType != Class.class){
cell.setCellValue((String)fieldType.getMethod(&setValue&, Object.class).invoke(null, val));
cell.setCellValue((String)Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
&fieldtype.&+val.getClass().getSimpleName()+&Type&)).getMethod(&setValue&, Object.class).invoke(null, val));
} catch (Exception ex) {
log.info(&Set cell value [&+row.getRowNum()+&,&+column+&] error: & + ex.toString());
cell.setCellValue(val.toString());
cell.setCellStyle(style);
* 添加数据(通过annotation.ExportField添加数据)
* @return list 数据列表
+ public &E& ExportExcel setDataList(List&E& list){
for (E e : list){
int colunm = 0;
Row row = this.addRow();
StringBuilder sb = new StringBuilder();
for (Object[] os : annotationList){
ExcelField ef = (ExcelField)os[0];
Object val =
// Get entity value
if (StringUtils.isNotBlank(ef.value())){
val = Reflections.invokeGetter(e, ef.value());
if (os[1] instanceof Field){
val = Reflections.invokeGetter(e, ((Field)os[1]).getName());
}else if (os[1] instanceof Method){
val = Reflections.invokeMethod(e, ((Method)os[1]).getName(), new Class[] {}, new Object[] {});
// If is dict, get dict label
if (StringUtils.isNotBlank(ef.dictType())){
val = DictUtils.getDictLabel(val==null?&&:val.toString(), ef.dictType(), &&);
}catch(Exception ex) {
// Failure to ignore
log.info(ex.toString());
this.addCell(row, colunm++, val, ef.align(), ef.fieldType());
sb.append(val + &, &);
log.debug(&Write success: [&+row.getRowNum()+&] &+sb.toString());
* 输出数据流
* @param os 输出数据流
+ public ExportExcel write(OutputStream os) throws IOException{
wb.write(os);
* 输出到客户端
* @param fileName 输出文件名
+ public ExportExcel write(HttpServletResponse response, String fileName) throws IOException{
response.reset();
response.setContentType(&application/octet- charset=utf-8&);
response.setHeader(&Content-Disposition&, & filename=&+Encodes.urlEncode(fileName));
write(response.getOutputStream());
* 输出到文件
* @param fileName 输出文件名
+ public ExportExcel writeFile(String name) throws FileNotFoundException, IOException{
FileOutputStream os = new FileOutputStream(name);
this.write(os);
* 清理临时文件
+ public ExportExcel dispose(){
wb.dispose();
* 导出测试
+// public static void main(String[] args) throws Throwable {
List&String& headerList = Lists.newArrayList();
for (int i = 1; i &= 10; i++) {
headerList.add(&表头&+i);
List&String& dataRowList = Lists.newArrayList();
for (int i = 1; i &= headerList.size(); i++) {
dataRowList.add(&数据&+i);
List&List&String&& dataList = Lists.newArrayList();
for (int i = 1; i &=1000000; i++) {
dataList.add(dataRowList);
ExportExcel ee = new ExportExcel(&表格标题&, headerList);
for (int i = 0; i & dataList.size(); i++) {
Row row = ee.addRow();
for (int j = 0; j & dataList.get(i).size(); j++) {
ee.addCell(row, j, dataList.get(i).get(j));
ee.writeFile(&target/export.xlsx&);
ee.dispose();
log.debug(&Export success.&);
Index: excel/fieldtype/AreaType.java
===================================================================
--- excel/fieldtype/AreaType.java (revision 0)
+++ excel/fieldtype/AreaType.java (revision 2)
@@ -0,0 +1,38 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.excel.
+import com.thinkgem.jeesite.common.utils.StringU
+import com.thinkgem.jeesite.modules.sys.entity.A
+import com.thinkgem.jeesite.modules.sys.utils.UserU
+ * 字段类型转换
+ * @author ThinkGem
+ * @version
+public class AreaType {
* 获取对象值(导入)
+ public static Object getValue(String val) {
for (Area e : UserUtils.getAreaList()){
if (StringUtils.trimToEmpty(val).equals(e.getName())){
* 获取对象值(导出)
+ public static String setValue(Object val) {
if (val != null && ((Area)val).getName() != null){
return ((Area)val).getName();
return &&;
Index: excel/fieldtype/OfficeType.java
===================================================================
--- excel/fieldtype/OfficeType.java (revision 0)
+++ excel/fieldtype/OfficeType.java (revision 2)
@@ -0,0 +1,38 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.excel.
+import com.thinkgem.jeesite.common.utils.StringU
+import com.thinkgem.jeesite.modules.sys.entity.O
+import com.thinkgem.jeesite.modules.sys.utils.UserU
+ * 字段类型转换
+ * @author ThinkGem
+ * @version
+public class OfficeType {
* 获取对象值(导入)
+ public static Object getValue(String val) {
for (Office e : UserUtils.getOfficeList()){
if (StringUtils.trimToEmpty(val).equals(e.getName())){
* 设置对象值(导出)
+ public static String setValue(Object val) {
if (val != null && ((Office)val).getName() != null){
return ((Office)val).getName();
return &&;
Index: excel/fieldtype/RoleListType.java
===================================================================
--- excel/fieldtype/RoleListType.java (revision 0)
+++ excel/fieldtype/RoleListType.java (revision 2)
@@ -0,0 +1,52 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.excel.
+import java.util.L
+import com.google.common.collect.L
+import com.thinkgem.jeesite.common.utils.StringU
+import com.thinkgem.jeesite.common.utils.Collections3;
+import com.thinkgem.jeesite.common.utils.SpringContextH
+import com.thinkgem.jeesite.modules.sys.entity.R
+import com.thinkgem.jeesite.modules.sys.service.SystemS
+ * 字段类型转换
+ * @author ThinkGem
+ * @version
+public class RoleListType {
+ private static SystemService systemService = SpringContextHolder.getBean(SystemService.class);
* 获取对象值(导入)
+ public static Object getValue(String val) {
List&Role& roleList = Lists.newArrayList();
List&Role& allRoleList = systemService.findAllRole();
for (String s : StringUtils.split(val, &,&)){
for (Role e : allRoleList){
if (StringUtils.trimToEmpty(s).equals(e.getName())){
roleList.add(e);
return roleList.size()&0?roleList:
* 设置对象值(导出)
+ public static String setValue(Object val) {
if (val != null){
@SuppressWarnings(&unchecked&)
List&Role& roleList = (List&Role&)
return Collections3.extractToString(roleList, &name&, &, &);
return &&;
Index: excel/annotation/ExcelField.java
===================================================================
--- excel/annotation/ExcelField.java (revision 0)
+++ excel/annotation/ExcelField.java (revision 2)
@@ -0,0 +1,59 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.excel.
+import java.lang.annotation.ElementT
+import java.lang.annotation.R
+import java.lang.annotation.RetentionP
+import java.lang.annotation.T
+ * Excel注解定义
+ * @author ThinkGem
+ * @version
+@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelField {
* 导出字段名(默认调用当前字段的“get”方法,如指定导出字段为对象,请填写“对象名.对象属性”,例:“area.name”、“office.name”)
+ String value() default &&;
* 导出字段标题(需要添加批注请用“**”分隔,标题**批注,仅对导出模板有效)
+ String title();
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
+ int type() default 0;
* 导出字段对齐方式(0:自动;1:靠左;2:居中;3:靠右)
+ int align() default 0;
* 导出字段字段排序(升序)
+ int sort() default 0;
* 如果是字典类型,请设置字典的type值
+ String dictType() default &&;
* 反射类型
+ Class&?& fieldType() default Class.
* 字段归属组(根据分组导出导入)
+ int[] groups() default {};
Index: excel/ImportExcel.java
===================================================================
--- excel/ImportExcel.java (revision 0)
+++ excel/ImportExcel.java (revision 2)
@@ -0,0 +1,370 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.utils.
+import java.io.F
+import java.io.FileInputS
+import java.io.IOE
+import java.io.InputS
+import java.lang.reflect.F
+import java.lang.reflect.M
+import java.util.C
+import java.util.C
+import java.util.D
+import java.util.L
+import org.apache.commons.lang3.StringU
+import org.apache.poi.hssf.usermodel.HSSFW
+import org.apache.poi.openxml4j.exceptions.InvalidFormatE
+import org.apache.poi.ss.usermodel.C
+import org.apache.poi.ss.usermodel.DateU
+import org.apache.poi.ss.usermodel.R
+import org.apache.poi.ss.usermodel.S
+import org.apache.poi.ss.usermodel.W
+import org.apache.poi.xssf.usermodel.XSSFW
+import org.slf4j.L
+import org.slf4j.LoggerF
+import org.springframework.web.multipart.MultipartF
+import com.google.common.collect.L
+import com.thinkgem.jeesite.common.utils.R
+import com.thinkgem.jeesite.common.utils.excel.annotation.ExcelF
+import com.thinkgem.jeesite.modules.sys.utils.DictU
+ * 导入Excel文件(支持“XLS”和“XLSX”格式)
+ * @author ThinkGem
+ * @version
+public class ImportExcel {
+ private static Logger log = LoggerFactory.getLogger(ImportExcel.class);
* 工作薄对象
+ private W
* 工作表对象
+ private S
* 标题行号
+ private int headerN
* 构造函数
* @param path 导入文件,读取第一个工作表
* @param headerNum 标题行号,数据行号=标题行号+1
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(String fileName, int headerNum)
throws InvalidFormatException, IOException {
this(new File(fileName), headerNum);
* 构造函数
* @param path 导入文件对象,读取第一个工作表
* @param headerNum 标题行号,数据行号=标题行号+1
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(File file, int headerNum)
throws InvalidFormatException, IOException {
this(file, headerNum, 0);
* 构造函数
* @param path 导入文件
* @param headerNum 标题行号,数据行号=标题行号+1
* @param sheetIndex 工作表编号
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(String fileName, int headerNum, int sheetIndex)
throws InvalidFormatException, IOException {
this(new File(fileName), headerNum, sheetIndex);
* 构造函数
* @param path 导入文件对象
* @param headerNum 标题行号,数据行号=标题行号+1
* @param sheetIndex 工作表编号
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(File file, int headerNum, int sheetIndex)
throws InvalidFormatException, IOException {
this(file.getName(), new FileInputStream(file), headerNum, sheetIndex);
* 构造函数
* @param file 导入文件对象
* @param headerNum 标题行号,数据行号=标题行号+1
* @param sheetIndex 工作表编号
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(MultipartFile multipartFile, int headerNum, int sheetIndex)
throws InvalidFormatException, IOException {
this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex);
* 构造函数
* @param path 导入文件对象
* @param headerNum 标题行号,数据行号=标题行号+1
* @param sheetIndex 工作表编号
* @throws InvalidFormatException
* @throws IOException
+ public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
throws InvalidFormatException, IOException {
if (StringUtils.isBlank(fileName)){
throw new RuntimeException(&导入文档为空!&);
}else if(fileName.toLowerCase().endsWith(&xls&)){
this.wb = new HSSFWorkbook(is);
}else if(fileName.toLowerCase().endsWith(&xlsx&)){
this.wb = new XSSFWorkbook(is);
throw new RuntimeException(&文档格式不正确!&);
if (this.wb.getNumberOfSheets()&sheetIndex){
throw new RuntimeException(&文档中没有工作表!&);
this.sheet = this.wb.getSheetAt(sheetIndex);
this.headerNum = headerN
log.debug(&Initialize success.&);
* 获取行对象
* @param rownum
+ public Row getRow(int rownum){
return this.sheet.getRow(rownum);
* 获取数据行号
+ public int getDataRowNum(){
return headerNum+1;
* 获取最后一个数据行号
+ public int getLastDataRowNum(){
return this.sheet.getLastRowNum()+headerN
* 获取最后一个列号
+ public int getLastCellNum(){
return this.getRow(headerNum).getLastCellNum();
* 获取单元格值
* @param row 获取的行
* @param column 获取单元格列号
* @return 单元格值
+ public Object getCellValue(Row row, int column){
Object val = &&;
Cell cell = row.getCell(column);
if (cell != null){
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
val = cell.getNumericCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_STRING){
val = cell.getStringCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA){
val = cell.getCellFormula();
}else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){
val = cell.getBooleanCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_ERROR){
val = cell.getErrorCellValue();
}catch (Exception e) {
* 获取导入数据列表
* @param cls 导入对象类型
* @param groups 导入分组
+ public &E& List&E& getDataList(Class&E& cls, int... groups) throws InstantiationException, IllegalAccessException{
List&Object[]& annotationList = Lists.newArrayList();
// Get annotation field
Field[] fs = cls.getDeclaredFields();
for (Field f : fs){
ExcelField ef = f.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==2)){
if (groups!=null && groups.length&0){
boolean inGroup =
for (int g : groups){
if (inGroup){
for (int efg : ef.groups()){
if (g == efg){
annotationList.add(new Object[]{ef, f});
annotationList.add(new Object[]{ef, f});
// Get annotation method
Method[] ms = cls.getDeclaredMethods();
for (Method m : ms){
ExcelField ef = m.getAnnotation(ExcelField.class);
if (ef != null && (ef.type()==0 || ef.type()==2)){
if (groups!=null && groups.length&0){
boolean inGroup =
for (int g : groups){
if (inGroup){
for (int efg : ef.groups()){
if (g == efg){
annotationList.add(new Object[]{ef, m});
annotationList.add(new Object[]{ef, m});
// Field sorting
Collections.sort(annotationList, new Comparator&Object[]&() {
public int compare(Object[] o1, Object[] o2) {
return new Integer(((ExcelField)o1[0]).sort()).compareTo(
new Integer(((ExcelField)o2[0]).sort()));
//log.debug(&Import column count:&+annotationList.size());
// Get excel data
List&E& dataList = Lists.newArrayList();
for (int i = this.getDataRowNum(); i & this.getLastDataRowNum(); i++) {
E e = (E)cls.newInstance();
int column = 0;
Row row = this.getRow(i);
StringBuilder sb = new StringBuilder();
for (Object[] os : annotationList){
Object val = this.getCellValue(row, column++);
if (val != null){
ExcelField ef = (ExcelField)os[0];
// If is dict type, get dict value
if (StringUtils.isNotBlank(ef.dictType())){
val = DictUtils.getDictValue(val.toString(), ef.dictType(), &&);
//log.debug(&Dictionary type value: [&+i+&,&+colunm+&] & + val);
// Get param type and type cast
Class&?& valType = Class.
if (os[1] instanceof Field){
valType = ((Field)os[1]).getType();
}else if (os[1] instanceof Method){
Method method = ((Method)os[1]);
if (&get&.equals(method.getName().substring(0, 3))){
valType = method.getReturnType();
}else if(&set&.equals(method.getName().substring(0, 3))){
valType = ((Method)os[1]).getParameterTypes()[0];
//log.debug(&Import value type: [&+i+&,&+column+&] & + valType);
if (valType == String.class){
String s = String.valueOf(val.toString());
if(StringUtils.endsWith(s, &.0&)){
val = StringUtils.substringBefore(s, &.0&);
val = String.valueOf(val.toString());
}else if (valType == Integer.class){
val = Double.valueOf(val.toString()).intValue();
}else if (valType == Long.class){
val = Double.valueOf(val.toString()).longValue();
}else if (valType == Double.class){
val = Double.valueOf(val.toString());
}else if (valType == Float.class){
val = Float.valueOf(val.toString());
}else if (valType == Date.class){
val = DateUtil.getJavaDate((Double)val);
if (ef.fieldType() != Class.class){
val = ef.fieldType().getMethod(&getValue&, String.class).invoke(null, val.toString());
val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
&fieldtype.&+valType.getSimpleName()+&Type&)).getMethod(&getValue&, String.class).invoke(null, val.toString());
} catch (Exception ex) {
log.info(&Get cell value [&+i+&,&+column+&] error: & + ex.toString());
// set entity value
if (os[1] instanceof Field){
Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
}else if (os[1] instanceof Method){
String mthodName = ((Method)os[1]).getName();
if (&get&.equals(mthodName.substring(0, 3))){
mthodName = &set&+StringUtils.substringAfter(mthodName, &get&);
Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
sb.append(val+&, &);
dataList.add(e);
log.debug(&Read success: [&+i+&] &+sb.toString());
return dataL
* 导入测试
+// public static void main(String[] args) throws Throwable {
ImportExcel ei = new ImportExcel(&target/export.xlsx&, 1);
for (int i = ei.getDataRowNum(); i & ei.getLastDataRowNum(); i++) {
Row row = ei.getRow(i);
for (int j = 0; j & ei.getLastCellNum(); j++) {
Object val = ei.getCellValue(row, j);
System.out.print(val+&, &);
System.out.print(&\n&);
Index: Encodes.java
===================================================================
--- Encodes.java (revision 0)
+++ Encodes.java (revision 2)
@@ -0,0 +1,151 @@
+ * Copyright (c)
springside.org.cn
+package com.thinkgem.jeesite.common.
+import java.io.UnsupportedEncodingE
+import java.net.URLD
+import java.net.URLE
+import org.apache.commons.codec.DecoderE
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.H
+import org.apache.commons.lang3.StringEscapeU
+ * 封装各种格式的编码解码工具类.
+ * 1.Commons-Codec的 hex/base64 编码
+ * 2.自制的base62 编码
+ * 3.Commons-Lang的xml/html escape
+ * 4.JDK提供的URLEncoder
+ * @author calvin
+ * @version
+public class Encodes {
+ private static final String DEFAULT_URL_ENCODING = &UTF-8&;
+ private static final char[] BASE62 = &ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&.toCharArray();
* Hex编码.
+ public static String encodeHex(byte[] input) {
return new String(Hex.encodeHex(input));
* Hex解码.
+ public static byte[] decodeHex(String input) {
return Hex.decodeHex(input.toCharArray());
} catch (DecoderException e) {
throw Exceptions.unchecked(e);
* Base64编码.
+ public static String encodeBase64(byte[] input) {
return new String(Base64.encodeBase64(input));
* Base64编码.
+ public static String encodeBase64(String input) {
return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
} catch (UnsupportedEncodingException e) {
return &&;
* Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
+// public static String encodeUrlSafeBase64(byte[] input) {
return Base64.encodeBase64URLSafe(input);
* Base64解码.
+ public static byte[] decodeBase64(String input) {
return Base64.decodeBase64(input.getBytes());
* Base64解码.
+ public static String decodeBase64String(String input) {
return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
} catch (UnsupportedEncodingException e) {
return &&;
* Base62编码。
+ public static String encodeBase62(byte[] input) {
char[] chars = new char[input.length];
for (int i = 0; i & input. i++) {
chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)];
return new String(chars);
* Html 转码.
+ public static String escapeHtml(String html) {
return StringEscapeUtils.escapeHtml4(html);
* Html 解码.
+ public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
* Xml 转码.
+ public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
* Xml 解码.
+ public static String unescapeXml(String xmlEscaped) {
return StringEscapeUtils.unescapeXml(xmlEscaped);
* URL 编码, Encode默认为UTF-8.
+ public static String urlEncode(String part) {
return URLEncoder.encode(part, DEFAULT_URL_ENCODING);
} catch (UnsupportedEncodingException e) {
throw Exceptions.unchecked(e);
* URL 解码, Encode默认为UTF-8.
+ public static String urlDecode(String part) {
return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
} catch (UnsupportedEncodingException e) {
throw Exceptions.unchecked(e);
Index: MacUtils.java
===================================================================
--- MacUtils.java (revision 0)
+++ MacUtils.java (revision 2)
@@ -0,0 +1,224 @@
+ * Copyright &
&a href=&https://github.com/thinkgem/jeesite&&JeeSite&/a& All rights reserved.
+package com.thinkgem.jeesite.common.
+import java.io.BufferedR
+import java.io.IOE
+import java.io.InputStreamR
+ * MAC地址工具
+ * @author ThinkGem
+ * @version
+public class MacUtils {
* 获取当前操作系统名称. return 操作系统名称 例如:windows,Linux,Unix等.
+ public static String getOSName() {
return System.getProperty(&os.name&).toLowerCase();
* 获取Unix网卡的mac地址.
* @return mac地址
+ public static String getUnixMACAddress() {
String mac =
BufferedReader bufferedReader =
Process process =
* Unix下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息
process = Runtime.getRuntime().exec(&ifconfig eth0&);
bufferedReader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line =
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
* 寻找标示字符串[hwaddr]
index = line.toLowerCase().indexOf(&hwaddr&);
if (index != -1) {
* 取出mac地址并去除2边空格
mac = line.substring(index + &hwaddr&.length() + 1).trim();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader.close();
} catch (IOException e1) {
e1.printStackTrace();
bufferedReader =
* 获取Linux网卡的mac地址.
* @return mac地址
+ public static String getLinuxMACAddress() {
String mac =
BufferedReader bufferedReader =
Process process =
* linux下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息
process = Runtime.getRuntime().exec(&ifconfig eth0&);
bufferedReader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line =
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf(&硬件地址&);
if (index != -1) {
* 取出mac地址并去除2边空格
mac = line.substring(index + 4).trim();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader.close();
} catch (IOException e1) {
e1.printStackTrace();
bufferedReader =
// 取不到,试下Unix取发
if (mac == null){
return getUnixMACAddress();
* 获取widnows网卡的mac地址.
* @return mac地址
+ public static String getWindowsMACAddress() {
String mac =
BufferedReader bufferedReader =
Process process =
* windows下的命令,显示信息中包含有mac地址信息
process = Runtime.getRuntime().exec(&ipconfig /all&);
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line =
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
* 寻找标示字符串[physical address]
index = line.toLowerCase().indexOf(&physical address&);
if (index != -1) {
if (line.split(&-&).length == 6){
index = line.indexOf(&:&);
if (index != -1) {
* 取出mac地址并去除2边空格
mac = line.substring(index + 1).trim();
index = line.toLowerCase().indexOf(&物理地址&);
if (index != -1) {
index = line.indexOf(&:&);
if (index != -1) {
* 取出mac地址并去除2边空格
mac = line.substring(index + 1).trim();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
bufferedReader.close();
} catch (IOException e1) {
e1.printStackTrace();
bufferedReader =
+ public static String getMac(){
String os = getOSName();
if (os.startsWith(&windows&)) {
mac = getWindowsMACAddress();
} else if (os.startsWith(&linux&)) {
mac = getLinuxMACAddress();
mac = getUnixMACAddress();
return mac == null ? && :
* 测试用的main方法.
* @param argc 运行参数.
+ public static void main(String[] argc) {
String os = getOSName();
System.out.println(&os: & + os);
if (os.startsWith(&windows&)) {
String mac = getWindowsMACAddress();
System.out.println(&mac: & + mac);
} else if (os.startsWith(&linux&)) {
String mac = getLinuxMACAddress();
System.out.println(&mac: & + mac);
String mac = getUnixMACAddress();
System.out.println(&mac: & + mac);
\ No newline at end of file
Index: PropertiesLoader.java
===================================================================
--- PropertiesLoader.java (revision 0)
+++ PropertiesLoader.java (revision 2)
@@ -0,0 +1,154 @@
+ * Copyright (c)
springside.org.cn
+ * $Id: PropertiesLoader.java -22 13:42:00Z calvinxiu $
+package com.thinkgem.jeesite.common.
+import java.io.IOE
+import java.io.InputS
+import java.util.NoSuchElementE
+import java.util.P
+import org.apache.commons.io.IOU
+import org.slf4j.L
+import org.slf4j.LoggerF
+import org.springframework.core.io.DefaultResourceL
+import org.springframework.core.io.R
+import org.springframework.core.io.ResourceL
+ * Properties文件载入工具类. 可载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的值,但以System的Property优先.
+ * @author calvin
+ * @version
+public class PropertiesLoader {
+ private static Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
+ private static ResourceLoader resourceLoader = new DefaultResourceLoader();
+ private final P
+ public PropertiesLoader(String... resourcesPaths) {
properties = loadProperties(resourcesPaths);
+ publ}

我要回帖

更多关于 欢乐斗地主用户协议 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信