自定义异常类
package com.cy.pj.common.exception;
/**自定义业务异常*/
public class ServiceException extends RuntimeException{
private static final long serialVersionUID = -5598865415547474216L;
public ServiceException() {
}
public ServiceException(String message) {
super(message);
}
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
public ServiceException(Throwable cause) {
super(cause);
}
public ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
//UnKnownAccountException
//
}
自定义异常类在serviceimpl中的使用
@Override
public int updateObject(SysRole entity, Integer[] menuIds) {
if (entity==null)
throw new IllegalArgumentException("保存对象不能为空");
if (StringUtils.isEmpty(entity.getName()))
throw new IllegalArgumentException("角色名不能为空");
if (menuIds==null||menuIds.length==0)
throw new ServiceException("必须为角色分配权限");
int rows = sysRoleDao.updateObject(entity);
if (rows==0)
throw new ServiceException("记录可能已经不存在");
sysRoleMenuDao.deleteObjectsByRoleId(entity.getId());
sysRoleMenuDao.insertObjects(entity.getId(), menuIds);
return rows;
}