.equals()和==在Java上整数(==工作但.equals没有!!)(.equals() and == in Java on Integer (== worked but .equals did not!!))
码:
call.getUserId().equals(ITConstants.SPECIALID) public static final Integer SPECIALID= 0;
POJO:
public class ImCall implements java.io.Serializable { private Integer userId;
HBM:
<property name="userId"> <column name="USER_ID" /> </property>
MySQL的:
int(11) is the datatype in MySQL
当UserId为零时“.equals()”不起作用(返回false)但令人惊讶的是“==”工作(返回true)。 我以为是因为Tomcat Server中的一些问题。所以我清理它并重新启动。 仍然是同一个问题。
但是几天后,我上面提到的问题再次出现了。 但现在,==和.equals()都有效!
所以,我的第一个问题是,当“==”有效并且“.equals()”没有时,是否存在任何情况。 第二个问题是,为什么“==”在这种情况下返回true?
编辑:
Getters仅返回Integer。
public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; }
Code:
call.getUserId().equals(ITConstants.SPECIALID) public static final Integer SPECIALID= 0;
POJO:
public class ImCall implements java.io.Serializable { private Integer userId;
HBM:
<property name="userId"> <column name="USER_ID" /> </property>
MySQL:
int(11) is the datatype in MySQL
When UserId was zero ".equals()" did not work(returned false) but surprisingly "==" worked(returned true). I thought it was because of some problem in Tomcat Server.So I cleaned it and restarted. Still the same issue.
But again after a couple of days,the problem I mentioned above did not reoccur. But now,both == and .equals() works!
So,my 1st question is,is there any situation when "==" works and ".equals()" does not. 2nd question is,Why "==" returns true in this case?
Edit :
Getters return Integer only.
public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; }
原文:https://stackoverflow.com/questions/20718592
最满意答案
你试过这个: -
<?= $this->Html->link('View',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-view");?> <?= $this->Html->link('Edit',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-edit");?>
要防止页面重新加载,请使用
href="javascript:void(0);"
创建链接href="javascript:void(0);"
如下: -<?= $this->Html->link('View','javascript:void(0);',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-view");?> <?= $this->Html->link('Edit','javascript:void(0);',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-edit");?>
如果你想通过jQuery(不是上面的代码)阻止,那么: -
$('link').click(function(e){ e.preventDefault(); //rest your code });
注意: - 确保在此代码之前添加了jQuery库,此代码必须位于页面底部。
Did you tried this:-
<?= $this->Html->link('View',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-view");?> <?= $this->Html->link('Edit',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-edit");?>
To prevent from page reload, create a link with
href="javascript:void(0);"
like below:-<?= $this->Html->link('View','javascript:void(0);',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-view");?> <?= $this->Html->link('Edit','javascript:void(0);',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-edit");?>
If you want to prevent through jQuery (not with the above code) then:-
$('link').click(function(e){ e.preventDefault(); //rest your code });
Note:- Make sure that jQuery library is added before this code and this code must be at the bottom of the page.
相关问答
更多-
你可以做 $('li.ui-tabs-selected a').addClass('yourclass'); 要手动添加一个类到任何选项卡,你可以假设你的ul有id #tabs $('#tabs li a').eq(1).addClass('yourclass'); //this will add class to second tab 已更新的答案使用select事件触发addClass() $('#wrap').tabs({ select: function(event, ui) { ...
-
试试这种方式: - $(function () { $('#lang_menu li a').attr('href', function (_, oldHref) { return oldHref + "#page1"; }); }); 演示 对于您的更新问题,您可以尝试这样的事情: 使用正则表达式替换url中的#part。 $(function () { $('#lang_menu li a').attr('href', function (_, oldHref) ...
-
是否有可能javascript代码段(document.getElementById)需要在jQuery document.ready回调中运行? 无论这是否是问题,我建议在document.ready回调中执行你的javascript,而不是在加载页面时让javascript运行。 Is it possible the javascript snippet (document.getElementById) needs to run within the jQuery document.ready cal ...
-
你试过这个: - = $this->Html->link('View',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-view");?> = $this->Html->link('Edit',array('#' => 'admin-view-' . $server->id,'data-target'=>"admin-edit");?> 要防止页面重新加载,请使用href="javascript:void(0);"创建链 ...
-
尝试这样的事情: $("#ax_campaign_nav a[data-ident=ax_models]").hide(); Try something like this: $("#ax_campaign_nav a[data-ident=ax_models]").hide();
-
-
将数据属性添加到表格单元格(Add data attribute to table cell)[2023-07-13]
.data()允许您存储与元素关联的数据。 它允许您使用已设置的data-*属性从元素获取数据,但它实际上不允许您向元素添加data-*属性。 .attr()允许您添加此属性。 $("td.row").each(function( index ) { $(this).attr("data-rowid", index); }); 您也可以使用@ CrazyTrain的解决方案,它似乎更有效: $("td.row").attr("data-rowid", function(index) { ... -
在单击处理程序中, this是单击的DOM元素。 使用$(this)将其转换为jQuery对象并使用attr : $(".myclass").click(function (e) { e.preventDefault(); console.log($(this).attr('name')); }); Inside a click handler this is the DOM element clicked. Use $(this) to convert it to a jQuer ...
-
jQuery:使用数据对象作为数据属性创建锚点(jQuery: Create anchor with an object of data as a data attribute)[2021-10-15]
您确定数据属性不起作用吗? 您将patientData作为任何空对象,因此如果未定义appt属性,则patientData仍为空: if (appt.appt_id) patientData.appt_id = appt.appt_id; if (appt.enc_id) patientData.enc_id = appt.enc_id; if (appt.person_id) patientData.person_id = appt.person_id; 尝试执行以下操作以查看患者的数据: consol ...