项目中犯的错切换不同学校

一、先看要实现的效果

在这里插入图片描述
点击切换学校报的错
在这里插入图片描述
2.调试步骤

  • (1)、看具体报错信息
    f12查看错误信息
QuerySyntaxException sql语句错误
'accountSchool.schoolId' [select count(distinct account.id)↵from com.dchip.school.web.model.po.Account account↵where accountSchool.schoolId = ?1 and account.status <> ?2]"
  • (2)、断点找到报错的位置(如果报错信息中明确指定了是代码中的哪一行 那就不需要断点)
    在这里插入图片描述

  • (3)、根据报错信息分析错误原因
    因为:

     1.根据后台断点查看sql语句没有qAccountSchool.schoolId
      account表中没有schoolId这个字段
     2.修改account中的accountId对应的是account表的id
     3.所以qAccount.id.eq(account.getAccountId())
    

表:在这里插入图片描述
3.正确代码

AccountAuthentic account = (AccountAuthentic) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if (account.getSchoolId() != -1) {
			predicates.add(qAccount.id.eq(account.getAccountId()));
		}
		predicates.add(qAccount.status.notIn(BaseConstant.AccountStatus.DelStatus.getTypeValue()));
		
		JPAQuery<Tuple> jPAQuery = jpaQueryFactory
				.select(qAccount.id, qAccount.username, qAccount.status, qAccount.type, qAccount.createTime, qAccount.latestLoginTime)
				.from(qAccount)
				.where(predicates.toArray(new Predicate[predicates.size()]))
				.groupBy(qAccount.id)
				.offset(pageNum * pageSize).limit(pageSize);

4,运行结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u014414110/article/details/86596441