Commit ac719fa0 by liuyongshuai

修改redis的读取单位代码的方式

parent 917cc01d
package com.xzxtshiro.util;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;
/**
* Created by Administrator on 2018/5/24.
*/
public class PropertiesUtils {
private Properties properties = new Properties();
/*
* 锟斤拷锟斤拷XXX.properties锟侥硷拷锟斤拷息
*/
public PropertiesUtils(String file) {
try {
InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream(file);
this.properties.load(in);
in.close();
}catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public Set getKeys() {
return this.properties.keySet();
}
public String getValue(String itemName) {
String str = "";
try {
str = new String(this.properties.getProperty(itemName).getBytes("ISO8859_1"), "GBK");
} catch (Exception e) {
System.err.println("PropertiesUtil: getValue " + e.getMessage());
}
return str;
}
}
...@@ -2,9 +2,7 @@ package com.xzxtshiro.util; ...@@ -2,9 +2,7 @@ package com.xzxtshiro.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.xzxtshiro.pojo.SysDictitem;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -23,13 +21,22 @@ public class RedisUtil { ...@@ -23,13 +21,22 @@ public class RedisUtil {
XzxtRestResult xzxtRestResult = new XzxtRestResult(); XzxtRestResult xzxtRestResult = new XzxtRestResult();
param.put("key", key); param.put("key", key);
//调用redisrest的服务 //调用redisrest的服务
String json = HttpClientUtil.doPost("http://127.0.0.1:9043/xzxt-rest/ReadRedisRest", param); String url = getRedisParam();
String json = HttpClientUtil.doPost(url+"/xzxt-rest/ReadRedisRest", param);
xzxtRestResult = JSONObject.parseObject(json, XzxtRestResult.class); xzxtRestResult = JSONObject.parseObject(json, XzxtRestResult.class);
if (!StringUtils.isBlank(xzxtRestResult.getData().toString())) { if (!StringUtils.isBlank(xzxtRestResult.getData().toString())) {
xzxtRestResult = xzxtRestResult.format(xzxtRestResult.getData().toString()); xzxtRestResult = xzxtRestResult.format(xzxtRestResult.getData().toString());
} }
return xzxtRestResult; return xzxtRestResult;
} }
public static String getRedisParam(){
PropertiesUtils propertiesUtil=new PropertiesUtils("resource/db.properties");
String host=propertiesUtil.getValue("redis.host");
String port = propertiesUtil.getValue("redis.port");
return host+":"+port;
}
//更新edis服务 //更新edis服务
/** /**
* redis存储服务 * redis存储服务
...@@ -40,10 +47,12 @@ public class RedisUtil { ...@@ -40,10 +47,12 @@ public class RedisUtil {
//查询参数 //查询参数
Map<String, String> param = new HashMap<>(); Map<String, String> param = new HashMap<>();
XzxtRestResult xzxtRestResult = new XzxtRestResult(); XzxtRestResult xzxtRestResult = new XzxtRestResult();
String url = getRedisParam();
param.put("ssdw", ssdw); param.put("ssdw", ssdw);
param.put("type", type); param.put("type", type);
//调用redisrest的服务 //调用redisrest的服务
String json = HttpClientUtil.doPost("http://127.0.0.1:9043/xzxt-rest/UpdateRedisRest", param); String json = HttpClientUtil.doPost(url+"/xzxt-rest/UpdateRedisRest", param);
if (!StringUtils.isBlank(json)) { if (!StringUtils.isBlank(json)) {
xzxtRestResult = XzxtRestResult.format(json); xzxtRestResult = XzxtRestResult.format(json);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment