BaseCRUDController是对BaseController更深一层的封装,它是一个泛型公共类。
该类抽象了以下几个方法,继承BaseCRUDControoler类,需要实现以下方法,如果没有,可以返回对应类型的默认值。
/**
* 操作员姓名
*
* @return
* @throws Exception
*/
public abstract String getEmpName() throws Exception;
/**
* 操作员ID
*
* @return
* @throws Exception
*/
public abstract String getEmpId() throws Exception;
/**
* 商家ID
*
* @return
* @throws Exception
*/
public abstract String getCompanyId() throws Exception;
/********************************************************
* 当前登录的用户类型
*
* @return
* @throws Exception
*/
public abstract int getUtype() throws Exception;
/********************************************************
* 当前登录的用户
*
* @return
* @throws Exception
*/
public abstract LoginUser getLoginUser() throws Exception;
根据项目需求,如果有权限控制,可以再封装此类,比如公司版系统,只能是公司版登录人员,那么可以写一个基类
public class BaseOrganizationController<M extends BaseModel<?>> extends BaseCRUDController<M>
其中要调用父类的构造方法
/**
* 构造方法
*/
public BaseOrganizationController() {
super();
}
子类继承BaseOrganizationController时,也要调用父类的构造方法,这样该类的CRUD操作都有了,权限也控制住了,用起来超级爽。当然,如果父类中的方法不满足业务逻辑,那可以重写父类的方法或者添加新方法实现,重写父类方法时,一定要在方法头上加@Override,比如:
@Override
public void save() {
try {
String id = get(ID);
Community m = getModel();
m.setOperId(SeqKit.getAID002());
m.setModifyUser(getEmpName());
m.setModifyTime(DateTime.now());
String townCode = m.getTownCode();
if (StrKit.notBlank(townCode)) {
String communityCode = communityService.getCommunityCode(townCode, id);
m.setCommunityCode(communityCode);
}
if (StrKit.isBlank(id)) {
m.setCreateRemark("新建社区");
m.setCreateTime(DateTime.now());
m.setCreateUser(getEmpName());
m.setModifyRemark("新建社区");
m.save();
} else {
m.setModifyRemark("修改社区");
m.update();
}
renderOK();
} catch (Exception e) {
renderErr(e);
}
}文档更新时间: 2020-06-30 16:52 作者:周光