1、数组判空
当定义数组时,为了防止数组越界异常,要对数据进行判空,并抛异常
if(ArrayUtil.isEmpty(xxx)){ //为空是true,不空为false
throw new Exception("XXXXX!")
}
2、校验只能是中文
public static boolean isChineseStr(String str){
Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
char c[] = str.toCharArray();
for(int i=0;i<c.length;i++){
Matcher matcher = pattern.matcher(String.valueOf(c[i]));
if(!matcher.matches()){
return false;
}
}
return true;
}
String str = "中文1";
if (!isChineseStr(str)){
System.out.println("不是");
}else{
System.out.println("是");
}
3、校验是否为纯数字
String BasicAccessNumber = "123";
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(BasicAccessNumber);
if (!isNum.matches()) {
System.out.println("非纯数字");
}
System.out.println("为纯数字");
4、校验是否有回车
String GroupCustomerName = "哈哈"+'\n'+"哈哈";
if (GroupCustomerName.indexOf('|') > -1 || GroupCustomerName.indexOf("\n") > -1){
System.out.println("有回车");
}else {
System.out.println("没回车");
}
5、StringUtils.contains()的用法
前边是否包含右边
String OperationType = "新增";
if (!StringUtils.contains("新增,更新,删除", OperationType)){
throw new Exception("操作类型不在取值范围内:新增,更新,删除");
}
6、时间格式转换
如果不是年月日时分秒,拼接为时分秒格式,通过长度来判断的
String skipStartDateStr = "2021-12-03 18:41:06";
Timestamp skipStartDate= null;
if (skipStartDateStr.length() < 11){
skipStartDate= Timestamp.valueOf(skipStartDateStr+" 00:00:00");
}else {
skipStartDate= Timestamp.valueOf(skipStartDateStr);
}
System.out.println(skipStartDate);
String skipStartDateStr= "2021-09-08";
System.out.println(skipStartDateStr.length());
Timestamp skipStartDate= Timestamp.valueOf(skipStartDateStr+" 00:00:00");
System.out.println(skipStartDate);
7、接口调用,5355账户资金科目查询接口
HashMap inMap = new HashMap();
inMap.put("busiType", "9");
inMap.put("billId", "19502133373");
inMap.put("targetItemId", 5960265);
IPublicQueryServiceSV publicQueryServiceSV = (IPublicQueryServiceSV) ServiceFactory.getService(IPublicQueryServiceSV.class);
Map map = publicQueryServiceSV.publicQueryService_5355(inMap);
8、ESOP接口调用
查询实例信息
Map inMap = new HashMap();
inMap.put("CUST_ID", "23010102722344");
inMap.put("BATCH_ID", "21232792098406");
IEsop2CrmBusiSV iEsop2CrmBusiSV = (IEsop2CrmBusiSV) ServiceFactory.getService(IEsop2CrmBusiSV.class);
iEsop2CrmBusiSV.queryHotelInfo(inMap);
9、集团状态修改整体逻辑
String zt = "";
int bs = -1;
int number = 0;
if (zt == "失效"){
bs = 6;
}else {
if (number == 0){
if (bs != 1){
bs = 3;
}
}else if (number > 5){
bs = 2;
}else if (number >0 && number <= 5){
if (zt == "沉默") {
bs = 5;
}else {
bs = 2;
}
}
}
System.out.println(bs);
10、Csf接口调用方式
Map paramMap = new HashMap();
paramMap.put("busiType","9");
paramMap.put("billId","19502133373");//1通过 0不通过
//paramMap.put("targetItemId","5960265");//1通过 0不通过
paramMap.put("targetItemId",5960265);
Map retMap = (Map) CsfServiceCaller.call("rboss_IQueryServiceCSV_publicQueryService_5355", paramMap);
if (retMap == null || retMap.get("fee") == null) throw new Exception("查询手机号费用异常");