1.将集合分割成逗号分割的字符串
List<String> zoneIds= Lists.newArrayList(); for(PropertyOrderDeptConfResp propertyOrderDeptConfResp :propertyOrderDeptConfRespList2){ zoneIds.add(propertyOrderDeptConfResp.getZoneId()); } zoneIdsString = String.join(",",zoneIds);
2.集合里是否包含某个字符串
list.contains(),返回值为布尔值
3.将逗号分割的字符串变成集合,并去除重复的字符串
List<String> zoneIds =Lists.newArrayList();
if(StringUtils.isNotEmpty(zoneIdsString)){
zoneIds =Arrays.asList((zoneIdsString.split(",")));
zoneIds = zoneIds.stream().distinct().collect(toList());
}
4.判断一个字符串是否为null并且不为空
StringUtil.isNotEmpty(字符串)
5.将一个对象转换成另一个对象,对象里面的参数要差不多相同,三种方法
如:
第一种:
public SettlementRecordResp findBySettlementRecordId(String id) { SettlementRecordQueryModel settlementRecordQueryModel = new SettlementRecordQueryModel(); settlementRecordQueryModel.setId(id); SettlementRecordDo settlementRecordDo = settlementRecordBusiness.getDetails(settlementRecordQueryModel); return BaseConverter.doToResp(settlementRecordDo,SettlementRecordResp.class); }
settlementRecordDo和SettlementRecordResp参数差不多
BaseConverter.doToResp()实现方法为:
public static <T> T doToResp(Object obj, Class<T> c) { if (null == obj) { return null; } String json = JsonUtils.toJson(obj); T t = JsonUtils.toObject(json, c); return t; }
第二种:
我们也可以使用BeanUtils.copyProperties方法进行转换,如:
BeanUtils.copyProperties(meterFeeApportionReq, meterFeeApportionEntity);
将meterFeeApportionReq对象里面的参数值拷贝到meterFeeApportionEntity中
第三种:
A和B做转换,A必须是C的子类,这样转换:
QueryRequestConverter.converQueryReqToQueryModel(serviceComplaintReportQueryReq,new CommunityServiceComplaintReportQueryModel())
其中
CommunityServiceComplaintReportQueryModel要是
BaseQueryModel的子类,converQueryReqToQueryModel实现方法如下:
private static Class queryReqClass; static { try { queryReqClass = Class.forName("com.mobcb.platform.service.common.dto.BaseQueryReq"); } catch(ClassNotFoundException e) { //log.error("find baseQueryReq class failed.", e); } }
public static <T extends BaseQueryModel> T converQueryReqToQueryModel(Object queryReq, T queryModel) { if (queryReq.getClass().getSuperclass().equals(queryReqClass)) { BeanUtils.copyProperties(queryReq, queryModel); return queryModel; } else { throw new IllegalArgumentException( "queryReq not baseQueryReq type, it is " + queryReq.getClass().getCanonicalName()); } }
6.在linux环境中,有时候和第三方系统对接,服务器在内网当中,看接口通不通
curl http://173.16.23.37:11111/api/v3/manageme/property/handleStatusUp ------------------看内网环境通不通
查看linux链接的方式有如下几种,具体啥区别大家可以去百度下哈:
命令查看链接:curl,wget ,telnet
在linux中可以用get和post直接调试,具体方法如下,checksession:false是有些接口需要额外带的请求头
用linux进行get请求:
curl -H "checksession:false" http://192.168.0.31:11112/api/v3/repair/management/property/AjHXhpBOCgEOJj7M?rnd=xsxsxaswwww
post请求:
curl -d "param1=value1¶m2=value2" "http://www.baidu.com"
curl 'http://11.20.131.96:8181/report/api/test/sb/getXmlForOpenApi' -X POST -d '{"kjnd": 2022, "kjqj": 6, "qyid": 905457455486291969, "sbszid": 2200010017}' --header "Content-Type: application/json"
在linux中通过进程号查看端口:
7.查询sql,参数在集合里和不包含
SELECT COUNT(id) FROM mob_community.community_repair_management WHERE ( check_status = 1 and zone_id in ( "AhLJXuN8HPeHE88R","AhNY6P9saegguju8" ) and accept_department_id <> "AjB247pY51dwkP3G" or accept_department_id is null )
不包含AjB247pY51dwkP3G