久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Spring Data Jpa實現自定義repository轉DTO

瀏覽:2日期:2023-08-23 13:22:38

近期項目中需要 關聯 幾張表再把字段轉出來,在這里記錄以下,我感覺網上寫的都不太規范和清晰。

@Entity@SqlResultSetMapping( name='TestMapping', entities = {@EntityResult( entityClass = com.xxx.xx.data.model.TestEntity.class, fields = {@FieldResult(name='id',column='id'),@FieldResult(name='localTime',column='time'),@FieldResult(name='maximumAppointment',column='maxAppointment'), }) })@NamedNativeQuery(name='getTestQuery', query='select tableC.id as id,tableB.time,tableC.maximumAppointment as maxAppointment from tableB ' +' inner join tableA on tableA.id = tableB.tableAId ' +' inner join tableC on tableB.id = tableC.tableBId ' +' inner join custom on custom.id = tableA.customId ' +'where ' +' tableA.locationId = :locationId' +' and custom.id = :customId' +' and tableB.deleted = false ', resultSetMapping='TestMapping')@Datapublic class TestEntity { @Id private String id; private LocalTime localTime; private Integer maximumAppointment;}

需要聲明接口:

@Repositorypublic interface TestEntityRepository extends JpaRepository<TestEntity,String> { @Query(name='getTestQuery') List<TestEntity> getTestQuery(String locationId, String customId);}

若不想聲明接口,那可以用EntityManager 來實現。

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 衡南县| 上饶市| 安泽县| 石棉县| 宣武区| 太保市| 襄垣县| 城口县| 平陆县| 安平县| 香格里拉县| 伊春市| 合川市| 崇仁县| 乃东县| 富阳市| 桃园县| 黄梅县| 柯坪县| 滨州市| 鸡东县| 鄂州市| 贺兰县| 洛浦县| 屏东市| 波密县| 乃东县| 井研县| 高邑县| 磐安县| 慈溪市| 巴彦淖尔市| 炉霍县| 华亭县| 塘沽区| 涿州市| 和田县| 尉氏县| 新疆| 禄丰县| 宾川县|