在我的班级中更改我的getter方法(如版本2)是不好的做法.
版本1:
public String getMyValue(){
return this.myValue
}
Run Code Online (Sandbox Code Playgroud)
版本2:
public String getMyValue(){
if(this.myValue == null || this.myValue.isEmpty()){
this.myValue = "N/A";
}
return this.myValue;
}
Run Code Online (Sandbox Code Playgroud) 在Windows环境中,您将在C:\ Users\user_name位置具有.m2文件夹,并且您将settings.xml文件复制到该文件夹,以便设置代理设置和nexus存储库位置等.
那么我必须在Ubuntu环境上做什么才能在安装maven之后获得类似的设置.
我已经针对我的代码在Eclipse中运行了PMD插件,并且我正在获得类似于下面所示代码的高优先级警告:
if(singleRequest !=null){
// do my work
}else{
// do my other work
}
Run Code Online (Sandbox Code Playgroud)
PMD说`Avoid if (x != y) ..; else ..
;
错误的描述如下:
In an "if" expression with an "else" clause, avoid negation in
the test. For example, rephrase:
if (x != y) diff(); else same();
as:
if (x == y) same(); else diff();
Most "if (x != y)" cases without an "else" are often return
Run Code Online (Sandbox Code Playgroud)
但我仍然无法理解对我的代码的影响.如果有人可以用一个例子来指导我,我将不胜感激.
我得到两个日期作为字符串值,我想检查开始时间早于结束时间.我比较它们,因为它没有将它们转换为使用日期SimpleDateFormat
,如下所示:
String startTime = "2013-01-02 14:25:56";
String endTime = "2013-01-02 14:30:56";
if(endTime.compareTo(startTime) > 0){
System.out.println("End time is greater than start time");
}
Run Code Online (Sandbox Code Playgroud)
是否真的有必要将它们转换为日期并进行比较?我会错过什么吗?我做对了吗?
我有这样的场景:
public void processData(String name,String value) {
/* line 1 */ MyDTO dto = new MyDTO();
/* line 2 */ dto.setName(name);
/* line 3 */ dto.setValue(value);
/* line 4 */ sendThroughJMSChannel(dto);
/* line 5 */ dto = null; //As a best practice, should I do this ?
}
Run Code Online (Sandbox Code Playgroud)
在第4行之后的程序中,我不需要dto
进一步处理.作为最佳实践,我应该设置dto
到null
在第5行,或者忽略它?
通过设置它null
,我期待快速垃圾收集.这是对的吗?
我开发了一个Web应用程序,在我的网页上有一些数据显示,包括常见的页眉,页脚,菜单和其他图像.所以我添加了一个小按钮作为打印预览,以便用户只能看到数据.用户点击打印预览按钮后,只有数据显示为弹出窗口,在弹出窗口中我添加了一个按钮调用打印,以便用户可以单击它并从该页面打印出来.
这个打印按钮直接调用onClick事件中的window.print(),它工作正常,我可以得到打印输出.
但我的问题是在我的打印页面上,我可以找到"打印"文本,这是按钮标题,在上面,我可以找到的网址是什么的 http://localhost/..............
那么有没有办法可以从我的打印页面中删除那些打印文本和网址.
非常感谢
这是打印预览按钮的功能.
function printPreView(reportCategory,reportType,transactionType,searchOption,customerRokaID,utilityCompany,fromDate,toDate,telcoName,bank){
var request = "selectedMenu="+reportCategory+"&loginStatus=success&criteria="+searchOption+"&customer="+customerRokaID+"&from="+fromDate+"&to="+toDate+"&nspTypes="+utilityCompany+"&trxTypes="+transactionType+"&options="+reportType+"&telcoTypes="+telcoName+"&bankTypes="+bank+"&printable=yes";
window.open ("report/showReport.action?"+request,null,"location=no,menubar=0,resizable=1,scrollbars=1,width=600,height=700");
}
Run Code Online (Sandbox Code Playgroud)
这是我如何放置我的打印按钮
<form>
<input type="button" value="Print" onClick="window.print() ">
</form>
Run Code Online (Sandbox Code Playgroud) 我正在处理Spring MVC应用程序,我遇到了一个问题,即在禁用时获取复选框的值.
在report.jsp页面中:
<form:checkbox type="checkbox" path="corporateColumn" id="corporateColumn" value="true" checked="checked" disabled="true" />
Run Code Online (Sandbox Code Playgroud)
在ReportForm.java中:
boolean corporateColumn ;
public boolean isCorporateColumn() {
return corporateColumn;
}
public void setCorporateColumn(boolean corporateColumn) {
this.corporateColumn = corporateColumn;
}
Run Code Online (Sandbox Code Playgroud)
在ReportController.java中;
boolean corporateColumn = reportDTO.isCorporateColumn(); // this evaluates to false
//Which expected as true when corporateColumn checkbox is checked
Run Code Online (Sandbox Code Playgroud)
除非对于复选框字段使用disabled ="true"(/ disabled ="$ {'true'}"),否则一切正常.
我在获取禁用文本字段的值时也遇到了类似的问题,并通过只读字段来克服它.所以我不确定Spring MVC在禁用时是否无法获取输入字段的值.
任何指导都会非常感激.
谢谢!
这是我的代码:
public static void main(String[] arg)
{
String x = null;
String y = "10";
String z = "20";
System.out.println("This my first out put "+x==null?y:z);
x = "15";
System.out.println("This my second out put "+x==null?y:z);
}
Run Code Online (Sandbox Code Playgroud)
我的输出是:
20
20
Run Code Online (Sandbox Code Playgroud)
但我期待这个:
This my first out put 10
This my second out put 20
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下为什么我得到"20"作为两个println调用的输出?
我通常按以下方式使用无限循环:
public static boolean start = false;
while(!start) {
doMyLogic();
}
Run Code Online (Sandbox Code Playgroud)
但是一位朋友说,您需要在while-true循环(如波纹管)中留一点延迟,否则可能会导致内存问题,也不是一个好习惯。
建议方式:
while(!start) {
Thread.sleep(few_miliseconds); // 500 ms
doMyLogic();
}
Run Code Online (Sandbox Code Playgroud)
请告知我建议方式的影响。我做对了吗?
I\xe2\x80\x99m 出现 PMD 红色违规
\n\n避免重新分配参数,例如“bankRequest”
\n\n这是我的方法
\n\n @Override\npublic BankDTO loadTariff(BankDTO bankRequest, int[] executionLevels) {\n double[] fee = null;\n for (int level : executionLevels) {\n\n // Check the tariff availability from execution level one to .....\n fee = loadCokaAndBankFee(bankRequest,level);\n\n if (fee != null) { // if fee found reload the bank request with new\n // amount\n bankRequest = reloadBankRequest(bankRequest, fee);\n break; // no need to go for any other level deep level cover //\n // here.\n } // if …
Run Code Online (Sandbox Code Playgroud) java ×8
jsp ×2
pmd ×2
class ×1
css ×1
date ×1
eclipse ×1
html ×1
javascript ×1
lazy-loading ×1
linux ×1
maven ×1
pom.xml ×1
printing ×1
println ×1
spring-mvc ×1
ubuntu ×1
while-loop ×1