全部博文(118)
分类: 系统运维
2012-11-21 17:00:58
Action层:
Long companyId = detailBean.getId();
String companyName = detailBean.getCompanyName().trim();
boolean i***ist = companyTask.doCompanyNameCheck(companyName, companyId == null ? -1 : companyId);
Dao层:
public boolean doCompanyNameCheck(String name, Long id) {
String hql = "select count(c.id) from Company c where c.companyName =? and c.id<>?";
Object ojb = this.findUnique(hql, new Object[] { name, id });
int count = ((Long) ojb).intValue();
if (count > 0) {
return true;
}
return false;
}
为什么一定要将Id主键传回来,是因为当我修改这个名称的时候,假如我修改了名称没保存我又想修改回来,如果没Id,系统会一直提示已经存在。加上Id就避免了此情形。