一、先看要实现的效果

项目中犯的错切换不同学校
点击切换学校报的错
项目中犯的错切换不同学校
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,运行结果
项目中犯的错切换不同学校

相关文章:

  • 2021-09-18
  • 2021-08-14
  • 2022-12-23
  • 2021-11-19
  • 2022-02-22
  • 2021-09-04
  • 2021-07-30
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-07-31
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案