我对sql查询有一个简单的问题。我必须得是非非,我尝试了多种创建方法,但效果不佳。该查询返回0,因为我在数据库中的记录为零。也许应该调整条件。感谢您的所有想法。
public boolean getAnalysisByUserId(final Integer userId) {
Objects.requireNonNull(userId, "Integer userId cannot be null.");
final Query query = this.manager.createQuery("select count(a) from AnalysisRequest a where" + " a.userId = :userId",
AnalysisRequest.class);
query.setParameter("userId", userId);
if (query.getSingleResult().equals(0)) {
return false;
}
return true;
}
答案 0 :(得分:0)
解决了,谢谢大家。
public boolean getAnalysisByUserId(final Integer userId) {
Objects.requireNonNull(userId, "Integer userId cannot be null.");
final Query query = this.manager
.createNativeQuery("select count(a.id) from AnalysisRequest a where a.userId = ?1");
query.setParameter(1, userId);
final Long result = (Long) query.getSingleResult();
return result != null && result > 0;
}