【发布时间】:2021-07-10 02:23:48
【问题描述】:
这是一个spring-boot项目,使用MVC结构
我有 3 种类型的需求延伸到BaseDemand
public class DropTableDemand extends BaseDemand{}
public class ExpandTableDemand extends BaseDemand{}
public class CreateTableDemand extends BaseDemand{}
我有 3 个服务来控制它们并用mybatis-plus DAO 保存它们
public class DropTableDemandService {
@Autowired
private DropTableDemandDao dropTableDemandDao;
public List<DropTableDemand> queryByOrgIDs(List<String> orgIDs, Integer page, Integer rows) {
if (page != null && rows != null) {
PageHelper.startPage(page, rows);
}
Weekend<DropTableDemand> weekend = Weekend.of(DropTableDemand.class);
WeekendCriteria<DropTableDemand, Object> criteria = weekend.weekendCriteria();
criteria.andIn(DropTableDemand::getTableOrg, orgIDs);
return dropTableDemandDao.selectByExample(weekend);
}
}
public class ExpandTableDemandService {
@Autowired
private ExpandTableDemandDao expandTableDemandDao;
public List<ExpandTableDemand> queryByOrgIDs(List<String> orgIDs, Integer page, Integer rows) {
if (page != null && rows != null) {
PageHelper.startPage(page, rows);
}
Weekend<ExpandTableDemand> weekend = Weekend.of(ExpandTableDemand.class);
WeekendCriteria<ExpandTableDemand, Object> criteria = weekend.weekendCriteria();
criteria.andIn(ExpandTableDemand::getTableOrg, orgIDs);
return expandTableDemandDao.selectByExample(weekend);
}
}
public class CreateTableDemandService {
@Autowired
private CreateTableDemandDao createTableDemandDao;
public List<CreateTableDemand> queryByOrgIDs(List<String> orgIDs, Integer page, Integer rows) {
if (page != null && rows != null) {
PageHelper.startPage(page, rows);
}
Weekend<CreateTableDemand> weekend = Weekend.of(CreateTableDemand.class);
WeekendCriteria<CreateTableDemand, Object> criteria = weekend.weekendCriteria();
criteria.andIn(CreateTableDemand::getTableOrg, orgIDs);
return createTableDemandDao.selectByExample(weekend);
}
}
DAO 就是这样的
public interface CreateTableDemandDao extends MyMapper<CreateTableDemand> {
}
public interface DropTableDemandDao extends MyMapper<DropTableDemand> {
}
这些服务中有很多重复的功能,但控制不同的类,如何简化它们
【问题讨论】:
标签: java spring-boot model-view-controller design-patterns