IDEA生成序列化ID

File -> setting -> Inspections -> Serializationissues

1
2
3
将其展开后将
serialzable class without serialVersionUID
打上勾

使用JAVA压缩文件

如下方法使用Ant版本1.6.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;
import java.io.File;
public class CompressionUtil {
public static void compress(String desPath, String srcPath){
File desFile = new File(desPath);// 目标文件
File srcFile = new File(srcPath);// 源文件
if (!srcFile.exists())
throw new RuntimeException("需要压缩的文件不存在");
Project project = new Project();
Zip zip = new Zip();
zip.setProject(project);
zip.setDestFile(desFile);
FileSet fileSet = new FileSet();
fileSet.setProject(project);
fileSet.setDir(srcFile);
zip.addFileset(fileSet);
zip.execute();
}
}

高德地图工具类(原创)

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
138
139
140
141
142
143
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* 获取高德地图坐标数据
* Created by dragon on 2017/8/10.
*/
public class GaodeMapGeographyUtil {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private final String KEY = "";
private RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(15000)
.setConnectTimeout(15000)
.setConnectionRequestTimeout(15000)
.build();
/**
* 方法入口1 : 通过城市名称,详细地址;获取高德地图经纬度
* @param city
* @param address
* @return 地理坐标
*/
public String getContantGeographical(String city,String address) {
String getUrl = "http://restapi.amap.com/v3/geocode/geo?batch=true&address=" + address + "&city=" + city + "&output=JSON&key=" + KEY;
String location = "";
try {
HttpGet httpGet = new HttpGet(getUrl);
String resultStr = sendHttpGet(httpGet);
JSONObject resultObj = JSON.parseObject(resultStr);
JSONArray geocodesArray = resultObj.getJSONArray("geocodes");
if (null != geocodesArray && geocodesArray.size() > 0){
JSONObject geocodesObj = JSON.parseObject(geocodesArray.get(0).toString());
location = geocodesObj.get("location").toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
/**
* 方法入口2 : 通过高德地图经纬度,逆向获取地址
* @param geographical
* @return 地址
*/
public String getContantAddressByGeographical(String geographical){
String getUrl = "http://restapi.amap.com/v3/geocode/regeo?key=" + KEY + "&location=" + geographical + "&poitype=&radius=1000&extensions=all&batch=false&roadlevel=0";
String address = "";
try {
HttpGet httpGet = new HttpGet(getUrl);
String resultStr = sendHttpGet(httpGet);
JSONObject resultObj = JSON.parseObject(resultStr);
Object regeocodeObj = resultObj.get("regeocode");
String jsonString = JSON.toJSONString(regeocodeObj);
JSONObject jsonObj = JSON.parseObject(jsonString);
address = jsonObj.get("formatted_address").toString();
} catch (Exception e) {
e.printStackTrace();
}
return address;
}
/**
* 方法入口3 : 测试方法,通过高德地图经纬度,逆向获取地址,POIS
* @param geographical
* @return 地址
*/
public String getContantAddressByGeographicalPois(String geographical){
String getUrl = "http://restapi.amap.com/v3/geocode/regeo?key=" + KEY + "&location=" + geographical + "&poitype=&radius=1000&extensions=all&batch=false&roadlevel=0";
String address = "";
double distance = 500;
try {
HttpGet httpGet = new HttpGet(getUrl);
String resultStr = sendHttpGet(httpGet);
JSONObject resultObj = JSON.parseObject(resultStr);
// 获取 [regeocode]
Object regeocodeObj = resultObj.get("regeocode");
String regeocodeObjToStr = JSON.toJSONString(regeocodeObj);
JSONObject jsonObj = JSON.parseObject(regeocodeObjToStr);
// 获取 [pois]
Object poisObj = jsonObj.get("pois");
String poisObjToStr = JSON.toJSONString(poisObj);
JSONArray poisArray = JSON.parseArray(poisObjToStr);
// 获取最近 [poi]
for (int i = 0; i < poisArray.size(); i++){
Object poiObj = poisArray.get(i);
String poiStr = JSON.toJSONString(poiObj);
JSONObject poi = JSON.parseObject(poiStr);
double poiDistance = Double.parseDouble(poi.get("distance").toString());
if (poiDistance < distance){
// 返回地址数据
distance = poiDistance;
address = poi.get("address").toString() + poi.get("name").toString();
}
}
logger.info("address = " + address + " , " +"pois.distance = " + distance);
} catch (Exception e) {
e.printStackTrace();
}
return address;
}
private String sendHttpGet(HttpGet httpGet) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
HttpEntity entity = null;
String responseContent = null;
try {
httpClient = HttpClients.createDefault();
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
entity = response.getEntity();
responseContent = EntityUtils.toString(entity, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseContent;
}
}

值得纪念的第一百篇博客

自2015年3月29日第一次注册域名,搭建博客开始不断的积累着。两年半的时间里,从大学到毕业,
如今已经积累到整整100篇博文了。希望通过写博客来记录我的技术成长和生活琐事。

在生活上,希望自己能够摆正心态,从心理学的角度来讲,心态是一个人的心理活动和状态的总和,
是人们对社会生活的反映和体验。心态对一个人的思想、情感、需要和欲望有着决定性的影响,它制
约着一个人对待工作、对待生活、对待事业的态度。心态是把双刃剑,积极的心态往往能够成就人生
,相反消极的心态则往往影响成功。

从大四的实习,到如今的毕业,有了属于自己的正式工作。在工作上,希望自己能记住这几句话:
工资不是用来支付给技能的,不要以为技能越高、工资自然应该越高。 工资是用来支付给责任的,责
任越大,工资越高。 涨工资,是因为承担了更大的责任。

愿自己继续坚持,加油!加油!加油!

HttpClient中GET请求

HttpClient版本4.5.2

1
2
3
4
5
private RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(15000)
.setConnectTimeout(15000)
.setConnectionRequestTimeout(15000)
.build();

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
private String sendHttpGet(HttpGet httpGet) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
HttpEntity entity = null;
String responseContent = null;
try {
httpClient = HttpClients.createDefault();
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
entity = response.getEntity();
responseContent = EntityUtils.toString(entity, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseContent;
}

入口:

1
2
HttpGet httpGet = new HttpGet(getUrl);
String resultStr = sendHttpGet(httpGet)

HttpURLConnection中GET请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static void httpURLConectionGET() {
try {
URL url = new URL("");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String line;
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
connection.disconnect();
System.out.println(sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
}

阿里云直播配置与使用(初体验)

完整的推流地址:
形如:rtmp://video-center.alivecdn.com/{AppName}/{StreamName}?vhost={yourdomain}

1
2
3
4
5
// 说明 video-center.alivecdn.com是直播中心服务器,允许自定义
// 例如您的域名是your.example.com(注意:该域名不可以和你的直播加速域名相同)
// 可以设置DNS,将您的 域名CNAME指向video-center.alivecdn.com即可
// app-name是应用名称,支持自定义,可以更改video-name是流名称,支持自定义
// 可以更改 vhost参数是最终在边缘节点播放的域名,即你的直播加速域名。

推流(OBS):
例如:rtmp://video.dragon-yuan.me/live_dragon/dragon?vhost=live.dragon-yuan.me
推流则需要配置如下:

1
2
// FMS(URL) 为 rtmp://video.dragon-yuan.me/live_dragon/
// 串流码 为 dragon?vhost=live.dragon-yuan.me

鉴权计算:

1
2
rtmp://video-center.alivecdn.com/{AppName}/{StreamName}?
vhost={yourdomain}&auth_key={timestamp}-{rand}-{uid}-{hashvalue}

字段描述

1
2
3
4
5
6
7
8
timestamp:失效时间=时间戳+有效时间,CDN服务器拿到请求后,首先会判断请求中的
失效时间是否小于当前时间,如果小于,则认为过期失效并返回HTTP 403错误。
rand:随机数,一般设成0
uid:暂未使用(设置成0)
hashvalue:通过md5加密算法计算出的32位验证串

推流则需要配置如下:

1
2
// FMS(URL) 为 rtmp://video.dragon-yuan.me/live_dragon/
// 串流码 为 dragon?vhost=live.dragon-yuan.me&auth_key=....

收看地址为:

1
http://live.dragon-yuan.me/live_dragon/dragon.flv?auth_key=....

VueJS中watch的使用

Watch可谓是 Vue中比较重要的部分,检测数据变动后视图更新的重要环节。

1
2
3
4
5
6
7
8
9
10
11
// data中定义一个aShow = false 作为显示变量
watch: {
'aForm.obj': function (val, oldVal) {
if (val !== '') {
this.aShow = true;
} else {
this.aShow = false;
}
}
}

GitHub进阶

1
git config --global http.postBuffer 524288000
1
2
3
4
git stash #储藏当前工作
git stash list #查看储藏的工作现场
git stash apply #恢复工作现场,stash内容并不删除
git stash pop #恢复工作现场,并删除stash内容

Spring中AOP对异常的处理

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
import com.exception.BusinessException;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.ThrowsAdvice;
public class ExceptionInterceptorLog implements ThrowsAdvice {
private static final Logger logger = LoggerFactory.getLogger(ExceptionInterceptorLog.class);
public ExceptionInterceptorLog() {
}
public void afterThrowing(Method method, Object[] args, Object target, BusinessException ex) {
logger.error("==>ExceptionInterceptorLog.BusinessException");
logger.error("==>errCode:" + ex.getCode() + " errMsg:" + ex.getMessage());
logger.error("==>" + ex.fillInStackTrace());
}
public void afterThrowing(Method method, Object[] args, Object target, Exception ex) {
logger.error("==>ExceptionInterceptorLog.Exception");
logger.error("==>Error class: " + target.getClass().getName());
logger.error("==>Error method: " + method.getName());
for(int i = 0; i < args.length; ++i) {
logger.error("==>args[" + i + "]: " + args[i]);
}
logger.error("==>Exception class: " + ex.getClass().getName());
logger.error("==>" + ex.fillInStackTrace());
logger.error("==> 堆栈信息{}", ex.toString(), ex);
}
}

在spring-config-aop.xml进行配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<!-- 异常信息 拦截 -->
<bean id="exceptionInterceptorLog" class="com.xescm.core.exception.ExceptionInterceptorLog"></bean>
<aop:config>
<aop:pointcut id="exceptionTrade" expression="
execution(* com.controller.*.*(..))
or execution(* com.controller.*.*(..))
"/>
<aop:advisor pointcut-ref="exceptionTrade" advice-ref="exceptionInterceptorLog"/>
</aop:config>
</beans>