这个程序明显不整洁。
public Test getTestBybh(String scbh)throws Exception{
if(bh == null){
throw new Exception("参数值为空!"); //此处异常被捕捉后就知道是啥错误了,一般的统一捕捉异常信息
}
return getHibernate......//我需要的
public Test getTestBybh(String scbh){
if(bh != null)
return getHibernate......//我需要的
else
return null;
}
我想这样写可能会好看点
public Test getTestBybh(String scbh){
if(!StringUtils.isBlank(scbh)){
return getHibernate......//我需要的
} else {
return null;
}
StringUtils是org.apache.commons.lang3这个包下面的。
public Test getTestBybh(String scbh){
if(bh != null){
return getHibernate......//我需要的;
}
return null;
}
public Test getTestBybh(String bh) {
return bh == null ? null : getHibernate();
}