public List findByCCateNameOrCourseName(String name){
List<QrCourseCategoryContainsCourses> qccclist = null;
//先判断输入的字符是能不能找到课程分类
QrCourseCategoriesExample cexample = new QrCourseCategoriesExample();
com.shopx5.pojo.QrCourseCategoriesExample.Criteria cc = cexample.createCriteria();
if (StringUtils.isNoneBlank(name)) {
cc.andNameLike("%"+name+"%");
}
List<QrCourseCategories> clist = qccService.selectByExample(cexample);
//如果分类名包含搜索词,列出所有的分类及课程
if(clist.size()!=0) {
for(QrCourseCategories QrCourseCategory:clist ) {
int id = QrCourseCategory.getId();
//直接逐条放进去就好了
//qccclist.containsAll(showSomeByCourseCate(id));
qccclist.addAll(showSomeByCourseCate(id));
//qccclist.add(showSomeByCourseCate(id).get(0));
}
}
以上代码一直在“qccclist.addAll(showSomeByCourseCate(id));”报错说空指针,一直以为是集合需要字段id不为空,可以另外的类似方法能返回到参数,并没有报错;后来改了一下这个,原来是集合初始化的问题。直接定义是不行是,应该是这样写:
List qccclist = new ArrayList();
一开始因为直接定义List没报错所以也没管,初始化一定要new 新对象,小细节要注意。