发表于: 2018-01-08 20:58:04
1 736
一.今天完成的主要事情
1.对代码进行重构
昨天其实有个疑问,对于重构时controller中的常量应该放在哪里
今天问了老大之后,老大说,常量定义遵循单一职责原则,这个常量在哪里会被用到,那么就在哪里定义该常量.
所以,case语句变为:
除此之外,继续之前在接口中用了String[]来定义常量数组,但是在接口中用常量数组非常不好,非常不利于变动,今天将这一部分进行了重构,将String[]中的元素都放在了spring的配置文件中,通过注入的方式来获取该数组中的内容
这样,如果以后要增加或者删除某些元素,只需要更改配置文件即可,不需要动代码
三是昨天发现代码中有很多的先根据条件查询ID,然后再通过IdList查询对象,但其实从接口的角度来看,并不需要关心Id是怎样获得的,我只需要知道最后的对象List即可,那我们其实是可以将获取IdList,然后再通过IdList获取对象List结合在一起,只调用一次service,这样减少了调用service的次数,性能上会更好一些
以下是一个封装好的获取对象List的实现
@Override
public List<SubjectExam> getSubjectExamListByStudentIdAndType(Long studentId, Integer type, Integer start, Integer limit) throws ServiceException, ServiceDaoException {
if (log.isInfoEnabled()) {
log.info(" get SubjectExamList by studentId,type,start,limit : " + studentId + " , " + type + " , " + start + " , " + limit);
}
// TODO 参数检查!
if (start == null) {
start = 0;
}
if (limit == null) {
limit = Integer.MAX_VALUE;
}
List<SubjectExam> subjectExamList= new ArrayList<>();
try {
List<Long> idList = dao.getIdList("getSubjectExamIdsByStudentIdAndType", new Object[]{studentId, type}, start, limit, false);
if (CollectionUtils.isNotEmpty(idList)){
subjectExamList = dao.getList(SubjectExam.class, idList);
}
} catch (DaoException e) {
log.error(" get subjectExamList wrong by studentId,type,start,limit) : " + studentId + " , " + type + " , " + start + " , " + limit);
log.error(e);
e.printStackTrace();
throw new ServiceDaoException(e);
}
if (log.isInfoEnabled()) {
log.info(" get SubjectExam list success : " + subjectExamList.size());
}
return subjectExamList;
}
核心就是中间标粗的部分,这部分将两个操作合并在一起
二,明天计划完成的事情
1.性能测试
2.和张帆交接
三.遇到的问题
暂无
四,收获
以上
五,项目进度情况
暂无延期风险
评论