sql相关

##学习总结

###1、sql优化
(1)、EXISTS 方案代替IN
(2)、不用is null、is not null等操作符,可以用a>0或者a>’’代替
(3)、对查询的表加别名
(4)、用TRUNCATE替代DELETE
(5)、用where代替having
(6)、建立索引提高效率
(7)、用exists替换distinct
(8)、sql语句用大写代替小写
(9)、用>=代替>
(10)、用Union替换or

Read More

Share

linux相关

##安装linux

###解决虚拟机中centos不能上网问题
1、首先将virtualbox设置为桥接网络,设置网卡为静态的,然后就可以了

1
2
3
4
5
6
7
8
9
10
11
设置IP和掩码
ifconfig eth0 192.168.5.40 netmask 255.255.255.0
最好编辑这个文件:
/etc/sysconfig/network-scripts/ifcfg-eth0 后面网卡可能不一样
设置网关
route add default gw 192.168.5.1
如果这样不行的话,永久修改网关
/etc/sysconfig/network 加入GATEWAY=192.168.1.1
vi /etc/resolv.conf
nameserver 8.8.8.8 #google域名服务器
nameserver 8.8.4.4 #google域名服务器

Read More

Share

smarty相关

##smarty

###基本页面语法
1、将数组转成一个字符串
$str=implode(“,”,$_POST[‘member_level’]);
2、将字符串转变成一个数组
$str=explode(“,”,$_POST[‘member_level’]);
3、smarty页面判断是否存在数组中

1
<{if in_array("0",$row.vipList)}>checked="checked"<{/if}>

Read More

Share

smarty语法详解

##Smarty

###语法
1、

##print_r

1
2
3
echo "<pre>";
print_r($myRes);
echo "</pre>";

Share

JAVA常用验证方法

#项目相关

##maven模块划分

###一、模块重用
1、命令行

1
2
cd nono-parent
call mvn clean install -Dmaven.test.skip=true

2、webAPP配置类
WebAppConfigure接口:得到域名、私有域名、顶级域名、静态域名、端口、contentPath、主题样式等配置
DefaultWebAppConfigure继承,可存放更多配置的变量

##Object

###requireNonNull/isNull
一般在构造函数中使用,或者直接进行验证;后者随时可用 前者返回T类型,后者返回bool

1
2
3
4
//会检测是否为空,如果为空,直接抛异常
public Foo(Bar bar) {
this.bar = Objects.requireNonNull(bar);
}

###常用验证类

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
* 验证邮箱地址格式
*/
public static boolean isEmail(String str) {
if (str == null || "".equals(str.trim()))
return true;
String regex = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
return match(regex, str);
}
/**
* 验证URL地址格式
*/
public static boolean isUrl(String str) {
String regex = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
return match(regex, str);
}
/**
* 验证是否IP地址
*/
public static boolean isIP(String str) {
String num = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
String regex = "^" + num + "\\." + num + "\\." + num + "\\." + num + "$";
return match(regex, str);
}
/**
* 验证固定电话号码
*/
public static boolean isTelephone(String str) {
String regex = "^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$";
return match(regex, str);
}
/**
* 验证手机号码
*
* 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
* 联通:130、131、132、152、155、156、185、186
* 电信:133、153、180、189、(1349卫通)
* 增加 17X 14X 19x号段
*/
public static boolean isMobile(String str) {
String regex = "^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\\d{8})$";
return match(regex, str);
}
/**
* 判断用户的身份证是否满足要求
* @param str
* @return
*/
public static boolean IDCardValidate(String str) {
String[] ValCodeArr = { "1", "0", "x", "9", "8", "7", "6", "5", "4",
"3", "2" };
String[] Wi = { "7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7",
"9", "10", "5", "8", "4", "2" };
String Ai = "";
// ================ 号码的长度 15位或18位 ================
if (str.length() != 15 && str.length() != 18) {
return false;
}
// =======================(end)========================
// ================ 数字 除最后以为都为数字 ================
if (str.length() == 18) {
Ai = str.substring(0, 17);
} else if (str.length() == 15) {
Ai = str.substring(0, 6) + "19" + str.substring(6, 15);
}
if (isNumeric(Ai) == false) {
return false;
}
// =======================(end)========================
// ================ 出生年月是否有效 ================
String strYear = Ai.substring(6, 10);// 年份
String strMonth = Ai.substring(10, 12);// 月份
String strDay = Ai.substring(12, 14);// 月份
if (isDate(strYear + "-" + strMonth + "-" + strDay) == false) {
return false;
}
GregorianCalendar gc = new GregorianCalendar();
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
try {
if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150
|| (gc.getTime().getTime() - s.parse(
strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) {
return false;
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (java.text.ParseException e) {
e.printStackTrace();
}
if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {
return false;
}
if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) {
return false;
}
// =====================(end)=====================
// ================ 地区码时候有效 ================
Hashtable h = GetAreaCode();
if (h.get(Ai.substring(0, 2)) == null) {
return false;
}
// ==============================================
// ================ 判断最后一位的值 ================
int TotalmulAiWi = 0;
for (int i = 0; i < 17; i++) {
TotalmulAiWi = TotalmulAiWi
+ Integer.parseInt(String.valueOf(Ai.charAt(i)))
* Integer.parseInt(Wi[i]);
}
int modValue = TotalmulAiWi % 11;
String strVerifyCode = ValCodeArr[modValue];
Ai = Ai + strVerifyCode;
if (str.length() == 18) {
if (Ai.toUpperCase().equals(str.toUpperCase()) == false) {
return false;
}
}
return true;
}
/**
* 功能:设置地区编码
*
* @return Hashtable 对象
*/
@SuppressWarnings("unchecked")
private static Hashtable GetAreaCode() {
Hashtable hashtable = new Hashtable();
hashtable.put("11", "北京");
hashtable.put("12", "天津");
hashtable.put("13", "河北");
hashtable.put("14", "山西");
hashtable.put("15", "内蒙古");
hashtable.put("21", "辽宁");
hashtable.put("22", "吉林");
hashtable.put("23", "黑龙江");
hashtable.put("31", "上海");
hashtable.put("32", "江苏");
hashtable.put("33", "浙江");
hashtable.put("34", "安徽");
hashtable.put("35", "福建");
hashtable.put("36", "江西");
hashtable.put("37", "山东");
hashtable.put("41", "河南");
hashtable.put("42", "湖北");
hashtable.put("43", "湖南");
hashtable.put("44", "广东");
hashtable.put("45", "广西");
hashtable.put("46", "海南");
hashtable.put("50", "重庆");
hashtable.put("51", "四川");
hashtable.put("52", "贵州");
hashtable.put("53", "云南");
hashtable.put("54", "西藏");
hashtable.put("61", "陕西");
hashtable.put("62", "甘肃");
hashtable.put("63", "青海");
hashtable.put("64", "宁夏");
hashtable.put("65", "新疆");
hashtable.put("71", "台湾");
hashtable.put("81", "香港");
hashtable.put("82", "澳门");
hashtable.put("91", "国外");
return hashtable;
}
private static boolean match(String regex, String str) {
if (isNullOrEmpty(str)) {
return false;
}
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
return matcher.lookingAt();
}
public static void main(String[] args) {
}
/**
* 功能:判断字符串是否为数字
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if (isNum.matches()) {
return true;
} else {
return false;
}
}
/**
* 功能:判断字符串是否为日期格式
*
* @param str
* @return
*/
public static boolean isDate(String strDate) {
Pattern pattern = Pattern
.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
Matcher m = pattern.matcher(strDate);
if (m.matches()) {
return true;
} else {
return false;
}
}

Share

spring知识整合

#spring知识整合

##JdbcTemplate
1、作用:jdbctemplate替我们完成了资源的创建以及释放工作,从而简化了我们对JDBC的操作,打开数据库连接、遍历查询结果、处理异常、处理事务、关闭数据库连接这些用户都无需再关注
2、用法:在bean中配置一下,给一个maindataSource即可

1
2
3
<bean id="mainJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="mainDataSource"/>
</bean>

Read More

Share

ThreadLocal使用

#ThreadLocal使用

##Thread介绍

###1、set方法

1
2
3
4
5
6
7
8
public void set(T value) {
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value);
}

Read More

Share

锁相关

#一、锁

  • 1、轻量锁 重量锁 公平锁 非公平锁是什么
Share

dubbo相关

#一、dubbo
1、理解
dubbo包括5个部分,提供者,消费者,容器(服务运行用的容器),注册中心(Registry),监控中心(Monitor)

  • 0.服务容器负责启动,加载,运行服务提供者。

  • 1.服务提供者在启动时,向注册中心注册自己提供的服务。

  • 2.服务消费者在启动时,向注册中心订阅自己所需的服务。

  • 3.注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。

  • 4.服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。

  • 5.服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

    Read More

Share

读写所相关

##读写比例过高的时候
1、使用读写锁:写入操作时候,锁住,不让读,读操作的时候,允许其它线程继续读

##避免等待事件死锁
1、使用一个GetLocks方法同时拿到2个锁

##多进程模式
1、

Read More

Share