概述
一、基础
1.端口被占用
cmd
netstat -ano | findstr 8080
taskkill -pid 进程 -f
2.json相关
1.jason字符串转json对象:
JSONObject jsonObject = JSON.parseObject(data);
2.json对象中取json对象:
JSONObject beans = jsonObject.getJSONObject("contexts");
3.json对象中根据key取value:
JSONObject value = (JSONObject) entry.getValue();
JSONArray dependencies = value.getJSONArray("dependencies");
3.保留四位小数
/**
* 将float类型的小数保留四位小数
* @param number float类型的小数
* @return
经过转换得到的四位小数
*/
public static float getNumber(float number){
DecimalFormat df = new DecimalFormat("#.####");
float f=Float.valueOf(df.format(number));
return f;
}
二、时间
1.Date设置时分秒
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Date endDate = calendar.getTime();
2.Date转换为yyyy-MM-dd :hh:mm:ss
(1)通过Util包中的Date获取
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(new Date()));
(2)通过Util包的Calendar 获取
Calendar calendar= Calendar.getInstance();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(calendar.getTime()));
(3)通过Util包的Calendar 获取时间,分别获取年月日时分秒
Calendar calendar=Calendar.getInstance();
int y=calendar.get(Calendar.YEAR);
int m=calendar.get(Calendar.MONTH);
int d=calendar.get(Calendar.DATE);
int h=calendar.get(Calendar.HOUR_OF_DAY);
int mi=calendar.get(Calendar.MINUTE);
int s=calendar.get(Calendar.SECOND);
System.out.println("现在时刻是"+y+"年"+m+"月"+d+"日"+h+"时"+mi+"分"+s+"秒");
(4)获取指定日期的时间戳
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = df.parse("2016-06-12 12:00:00");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
long time = cal .getTimeInMillis();
3.获取24小时前的时间
endDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(endDate);
c.set(Calendar.HOUR_OF_DAY,c.get(Calendar.HOUR_OF_DAY) - 24);
startDate = c.getTime();
4.页面时间转换展示
<f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" />
5.测时
long
startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
System.out.println("程序运行时间:" + (endTime - startTime) + "ms");
二、集合
1.List转Map
Map<String,LineParam> map = lineparams.stream().filter(e->StringUtils.isNotBlank(e.getEms_id())).collect(Collectors.toMap(e->e.getEms_id(), e->e,(value1, value2 )-> value2));
Map<String,AlarmMessage> map = alarmMsgs.stream().collect(Collectors.toMap(e->e.getId(), e->e));
2.List去重
List<String> myList = list.stream().distinct().collect(Collectors.toList());
3.List排序
Collections.sort(equipmentEvaluateList, Comparator.comparing(ProtectionEquipmentEvaluate::getEvaluateTime, (t1, t2) -> t2.compareTo(t1)));
regularInspectionPlans.sort(Comparator.comparing(RegularInspectionPlan::getPlanInspectDate,Comparator.nullsFirst(Date::compareTo)).reversed());
4.两个List组合
aCLineSegments = cimManger.getAcLineSegmentByNameAndLength(lineparamName,Float.parseFloat(selectVoltage));
lineparams = lineParamManager.getLineparamByNameAndBusAndSubStation(lineparamName, null,null,Float.parseFloat(selectVoltage));
Map<String,LineParam> map = lineparams.stream().filter(e->StringUtils.isNotBlank(e.getEms_id())).collect(Collectors.toMap(e->e.getEms_id(), e->e,(value1, value2 )-> value2));
aCLineSegments.forEach(e->{
String id = e.getId();
LineParam lineparamDTO = map.get(id);
lineParamVO = new LineParamVO();
lineParamVO.setLineparamDTO(lineparamDTO);
lineParamVO.setaCLineSegmentVO(e);
lineParamList.add(lineParamVO);
});
5.map分组
Map<String, List<ProtectionEquipmentEvaluate>> planMap = equipmentEvaluateList.stream().collect(Collectors.groupingBy(ProtectionEquipmentEvaluate::getPlanId));
6.map遍历
for (Entry<String, Substation> en : map.entrySet()) {}
7.list遍历
Iterator<SecondaryEquipmentLedger> it = ledgers.iterator();
while (it.hasNext()) {
Ledger plan = (Ledger) it.next();
if(null==plan.getLastRegularInspectTime()) {
it.remove();
}
}
三、页面知识
1.高级查询
<s:advancedQuery></s:advancedQuery>
2.名称查询模板
页面
<p:autoComplete id="quaryName"
value="#{Controller.quaryName}"
completeMethod="#{Controller.quaryNameSelect}"
placeholder="名称查询" style="margin-right:5px;"
scrollHeight="400" dropdown="true">
</p:autoComplete>
后台
public List<String> quaryNameSelect(String query) {
Set<String> names = new LinkedHashSet<String>();
for (Entry<String, ResourceMetricsData> en : allResourceDataMap.entrySet()) {
String name = en.getKey();
if (StringUtils.isNotBlank(name)) {
String nameHead = PingYinUtil.getPingYinHeader(name);
if (nameHead.toLowerCase().contains(query)) {
names.add(name);
}
if (name.contains(query)) {
names.add(name);
}
}
}
return new ArrayList<String>(names);
}
3.时间查询模板
<p:outputLabel for="startDate" value="时间:" />
<p:calendar id="startDate" navigator="true"
value="#{historyMonitorDetailsController.startDate}"
pattern="yyyy-MM-dd HH:mm:ss"
maxdate="#{historyMonitorDetailsController.endDate}"
size="18">
<p:ajax event="dateSelect" update="endDate" />
</p:calendar>
<p:outputLabel for="endDate" value="至 "
style="margin-right:5px;margin-left:5px;" />
<p:calendar id="endDate" navigator="true"
value="#{historyMonitorDetailsController.endDate}"
pattern="yyyy-MM-dd HH:mm:ss"
mindate="#{historyMonitorDetailsController.startDate}"
size="18" style="margin-right:5px">
<p:ajax event="dateSelect" update="startDate" />
</p:calendar>
4.点击弹窗
<p:commandButton value="查看" icon="pi pi-file-o" class="p-mr-2 pml-2"
actionListener="#{protectionController.getPlanDetails()}"
update="form:planDetails dataTbForm:dataTb toolbarForm:toolbar"
oncomplete="PF('planDetails').show()" />
<p:dialog widgetVar="planDetails" header="计划详情" modal="true"
focus="planDetails" id="planDetails" width="1400" height="700">
<p:dataTable
value="#{proController.quipments}"
var="item" paginator="true" id="dataTable3" emptyMessage="无记录"
rowKey="#{act.id}" rows="20" rowIndexVar="ite"
paginatorTemplate="{Customization} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100" paginatorPosition="bottom"
style="text-align:center;margin-top:3px">
<f:facet name="{Customization}">
<p:outputLabel
value="总计:#{proController.quipments.size()} 条记录"
style="margin-right:20px;" />
</f:facet>
<p:column headerText="序号" style="width:5%;text-align:center;">
<h:outputText value="#{ite+1}" />
</p:column>
<p:column headerText="保护名称" style="text-align:center;">
<h:outputText value="#{item.name}" />
</p:column>
</p:dataTable>
</p:dialog>
5.隐藏数据
<h:inputHidden id="type" value="#{waveEquipmentController.type}" />
6.primeface分块
<div class="p-grid">
<div class="p-col-6">6</div>
<div class="p-col-6">6</div>
</div>
7.页面定时刷新
<p:poll interval="2" listener="#{systemResourceController.initData}" update="dataTb"/>
8.懒加载
9.工具栏合并
<p:splitButton value="批量操作" >
<p:menuitem value="置为非故障" icon="pi pi-exclamation-triangle"
update="form:dataTb form:msgs" styleClass="p-mr-2 "
oncomplete="PF('confirmDialog1').show();"/>
<p:menuitem value="置为故障" icon="pi pi-exclamation-triangle"
update="form:dataTb form:msgs" styleClass="p-mr-2 "
oncomplete="PF('confirmDialog2').show();"/>
<p:menuitem value="批量发布" icon="pi pi-exclamation-triangle"
update="form:dataTb form:msgs" styleClass="p-mr-2 "
oncomplete="PF('confirmPublishDialog').show();"/>
</p:splitButton>
<p:dialog id="confirmDialog1" widgetVar="confirmDialog1" modal="true"
header="提示" width="220" height="120" closable="false">
确定要修改故障状态吗?<br />
<br />
<br />
<p:commandButton value="是" process="@form"
styleClass="ui-confirmdialog-yes" icon="pi pi-check"
oncomplete="PF('confirmDialog1').hide();"
actionListener="#{faultReportController.batchSetToNoFault}"
update="form:dataTb form:msgs" style="margin-right: 10px" />
<p:commandButton value="否" styleClass="ui-confirmdialog-no"
icon="pi pi-ban" oncomplete="PF('confirmDialog1').hide();"
update="form:dataTb"
actionListener="#{faultReportController.queryByTime}" />
</p:dialog>
10.是否发布勾选框
<p:column>
<h:outputText value="是否发布" />
<p:commandLink oncomplete="PF('alertInfoDialog').show()"
title="提示">
<i class="fa fa-question-circle" ></i>
</p:commandLink>
</p:column>
<p:column colspan="1">
<p:selectBooleanCheckbox
value="#{faultReportController.selected.sendToOms}" />
</p:column>
//
<p:dialog widgetVar="alertInfoDialog" modal="true" closable="true"
draggable="true" width="260" height="60">
<p:outputLabel value="选中即发布到生产、调度等系统" />
</p:dialog>
11.插入一个页面
被插入页面不能引入模板,不能有<ui:>标签;
<p:tab title="系统监控">
<div id="systemResource">
<ui:include src="systemResourceMonitorHistory.xhtml" />
</div>
</p:tab>
四、datable相关
1.dataTable行扩展
(1)是否默认展开:
expandedRow="true"
(2)列首添加:
<p:column style="width:2rem">
<p:rowToggler />
</p:column>
(3)列末添加:ite为原表格字段;
<p:rowExpansion>
<p:dataTable var="ite" emptyMessage="暂无数据"
value="#{item.envDetails}">
<p:column headerText="名称" style="text-align:center" filterable="false"
rendered="#{ite.showDetails}">
<h:outputText value="#{ite.name}" />
</p:column>
<p:column headerText="内容" style="text-align:center" filterable="false"
rendered="#{ite.showDetails}">
<h:outputText value="#{ite.value}" />
</p:column>
</p:dataTable>
</p:rowExpansion>
2.dataTable添加表头或者全局搜索
(1)添加搜索框
<f:facet name="header">
<div class="p-d-flex p-jc-end">
<p:inputText id="globalFilter" onkeyup="PF('dataTb').filter()"
style="width:300px"
placeholder="Search all properties" />
</div>
</f:facet>
(2)添加属性
filteredValue="#{systemResourceMonitorEnvironmentController.environmentModels}"
globalFilterFunction="#{systemResourceMonitorEnvironmentController.globalFilterFunction}"
(3)后台添加过滤集合和方法
普通表格:
private List<EnvironmentModel> environmentModels = new ArrayList<>();
public boolean globalFilterFunction(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (!LangUtils.isNotBlank(filterText)) {
return true;
}
filterText = filterText.toUpperCase();
boolean booleanData1 = customer.getTitle().toLowerCase().toUpperCase().contains(filterText);
boolean booleanData2 = customer.getEnvDetails().toLowerCase().toUpperCase().contains(filterText);
return booleanData1 || booleanData2;
}
表中表:
private List<EnvironmentModel> environmentModels = new ArrayList<>();
public boolean globalFilterFunction(Object value, Object filter, Locale locale) {
String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase();
if (!LangUtils.isNotBlank(filterText)) {
EnvironmentModel customer = (EnvironmentModel) value;
for(EnvDetailsModel model:customer.getEnvDetails()) {
model.setShowDetails(true);
}
return true;
}
filterText = filterText.toUpperCase();
boolean booleanData1;
boolean booleanData2 = false;
EnvironmentModel customer = (EnvironmentModel) value;
booleanData1 = customer.getTitle().toLowerCase().toUpperCase().contains(filterText);
if(booleanData1) {
EnvironmentModel customers = (EnvironmentModel) value;
for(EnvDetailsModel model:customers.getEnvDetails()) {
model.setShowDetails(true);
}
return true;
}else {
for (int i = 0; i < customer.getEnvDetails().size(); i++) {
boolean valueBoolean = customer.getEnvDetails().get(i).getName().toUpperCase().contains(filterText);
boolean valueBoolean2 = customer.getEnvDetails().get(i).getValue().toUpperCase().contains(filterText);
if(valueBoolean||valueBoolean2) {
booleanData2 = true;
customer.getEnvDetails().get(i).setShowDetails(true);
}else {
customer.getEnvDetails().get(i).setShowDetails(false);
}
}
return booleanData2;
}
}
3.表格内链接弹出页面
页面
<p:commandLink
actionListener="#{patrolController.openPatrolResultDialog(act)}"
title="巡视结果详情" style="text-align: center">
<i class="pi pi-map" style="color: #276ee8"></i>
</p:commandLink>
//<ui:define name="contentend">
//<script>
function openPatrolResultReport(path) {
if (path) {
layer.open({
type : 2,
maxmin : false,
area : [ '80%', '90%' ],
fixed : false, //不固定
title : '详情',
maxmin : true,
content : path,
});
}
}
后台
public void openPatrolResultDialog(PatrolResultModel patrolResult){
selectlDevice = patrolResult;
String path = "";
String selectlDeviceId = selectlDevice.getId();
path = "/ui/dataview/patrol/patrolAbnormalResultDetails.xhtml?selectlDeviceId=" + selectlDeviceId;
PrimeFaces.current().executeScript("openPatrolResultReport('" + path + "')");
}
弹出页面获取参数
String deviceId = getParameter("selectlDeviceId");
4.DataTable添加筛选
showLimit控制展示状态true or false;
<f:facet name="actions">
<p:outputLabel value="展示全部:" />
<p:toggleSwitch
style="float:right;margin-top: -3px;"
id="switch" value="#{bannerController.showLimit}">
<p:ajax listener="#{bannerController.searchByCondition}"
update="leftForm" />
</p:toggleSwitch>
</f:facet>
5.单元格数据部分显示
<p:column headerText="发送内容" width="150" style="text-align:center;" exportFunction="#{waitingSendMessageListController.messageContent(item)}">
<h:outputText style="white-space:pre-wrap;display:block;"
value="#{item.content}" escape="false"
rendered="#{item.content.length()<=80}" />
<p:outputPanel rendered="#{item.content.length()>80}">
<p:commandLink style="white-space:pre-wrap;"
value="#{item.content.substring(0,80)}..."
update=":dataTbForm:textDetail"
oncomplete="PF('carOP').show('#{component.clientId}')">
<f:setPropertyActionListener value="#{item.content}"
target="#{waitingSendMessageListController.selectedContent}" />
</p:commandLink>
</p:outputPanel>
</p:column>
//
<p:overlayPanel style="width:400px" widgetVar="carOP"
showEffect="fade" hideEffect="fade" dismissable="true">
<p:outputPanel id="textDetail" style="text-align:center;">
<h:outputText
value="#{waitingSendMessageListController.selectedContent}" />
</p:outputPanel>
</p:overlayPanel>
后台
private String selectedContent = "";
public String messageContent(DefectMessage defect) {
return defect.getContent();
}
最后
以上就是留胡子太阳为你收集整理的平时写着玩的全部内容,希望文章能够帮你解决平时写着玩所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复