很简单的写法,但经常忘记,见下:
DTO定义:
public interface OrgVO {
Long getId();
String getName();
}
查询SQL定义:
public interface OrgRepository extends JpaRepository<GeneralUser,Long> {
@Query(value = """
SELECT `id`,`name` FROM camera WHERE is_deleted=0 UNION ALL
SELECT `id`,`name` FROM org WHERE is_deleted=0 UNION ALL
SELECT `id`,`name` FROM device WHERE is_deleted=0
""", nativeQuery = true)
List<OrgVO> findAllOrgIdAndName();
}