刘韬 6 лет назад
Родитель
Сommit
6150648320

+ 74 - 0
PacsOnline_Wechat_Patient/src/main/java/com/zskk/common/JsonSerializer.java

@@ -0,0 +1,74 @@
+package com.zskk.common;
+
+import java.io.UnsupportedEncodingException;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.jfinal.plugin.redis.serializer.ISerializer;
+
+public class JsonSerializer implements ISerializer {
+
+	@Override
+	public byte[] keyToBytes(String key) {
+		return this.str2Byte(key);
+	}
+
+	@Override
+	public String keyFromBytes(byte[] bytes) {
+		if(bytes == null || bytes.length == 0){
+			return null;		
+		}
+		
+		return this.byte2Str(bytes);
+	}
+
+	@Override
+	public byte[] fieldToBytes(Object field) {
+		String json = JSON.toJSONString(field);
+		return this.str2Byte(json);
+	}
+
+	@Override
+	public Object fieldFromBytes(byte[] bytes) {
+		if(bytes == null || bytes.length == 0){
+			return null;		
+		}
+		
+		String json = this.byte2Str(bytes);
+		return JSON.parseObject(json);
+	}
+
+	@Override
+	public byte[] valueToBytes(Object value) {
+		String json = JSON.toJSONString(value, SerializerFeature.WriteClassName);
+		return this.str2Byte(json);
+	}
+
+	@Override
+	public Object valueFromBytes(byte[] bytes) {
+		if(bytes == null || bytes.length == 0){
+			return null;		
+		}
+		
+		String json = this.byte2Str(bytes);
+		return JSON.parse(json);
+	}
+	
+	private String byte2Str(byte[] bytes){
+		try {
+			return new String(bytes, "UTF-8");
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		return null;		
+	}
+	
+	private byte[] str2Byte(String str){
+		try {
+			return str.getBytes("UTF-8");
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		return null;	
+	}
+}

+ 4 - 2
PacsOnline_Wechat_Patient/src/main/java/com/zskk/common/ZskkConfig.java

@@ -79,9 +79,11 @@ public class ZskkConfig extends JFinalConfig {
 		me.add(arp);
 
 //         使用redis分布accessToken
-//         RedisPlugin redisPlugin = new RedisPlugin("weixin_patient", "127.0.0.1", 6379, 1000);
+         RedisPlugin redisPlugin = new RedisPlugin("Yunzhen", "127.0.0.1", 6379, 1000);
 //         redisPlugin.setSerializer(JdkSerializer.me); // 需要使用fst高性能序列化的用户请删除这一行(Fst jar依赖请查看WIKI)
-//         me.add(redisPlugin);
+ 		redisPlugin.setSerializer(new JsonSerializer());
+
+         me.add(redisPlugin);
     }
 
     public void configInterceptor(Interceptors me) {