【发布时间】:2016-12-26 10:14:59
【问题描述】:
@Repository
public interface WANRepository extends JpaRepository<WANConfiguration,Long>{
@Query("select ads from WANConfiguration as ads where ?1 BETWEEN ads.minAge AND ads.maxAge AND ads.expiryTime >?2 and ads.region=?3 and ads.gender=?4")
List<WANConfiguration> findByAllAdsForUser(Integer userAge,Date currentTime,String region, String gender);
}
这里是调用代码
List<WANConfiguration> list = fanRepository.findByAllAdsForUser(userAgeInYear, new Date(),userLocation.getRegionName(), user.getGender().name());
现在有一种情况我想传递默认区域,即 userLocation.getRegionName(),那么我该怎么做?在 db 和存储库或 Query 中需要做哪些更改?
【问题讨论】:
-
你能清楚你在这里问什么吗?当
userLocation.getRegionName()为空/null 等时,您想传递默认区域吗? -
是的,没错...我想在默认区域为空或为空时传递默认区域
标签: spring jpa orm spring-data spring-data-jpa