标签: spring-projections

春季预测没有返回国家细节

我有一个Country和State表,我已经将其与Spring Data JPA集成在一起.我public Page<CountryDetails> getAllCountryDetails在CountryServiceImpl中创建了一个函数,用于获取所有Country和相应的State详细信息.该服务工作正常,给我以下输出:

{
  "content": [
    {
      "id": 123,
      "countryName": "USA",
      "countryCode": "USA",
      "countryDetails": "XXXXXXXX",
      "countryZone": "XXXXXXX",
      "states": [
        {
          "id": 23,
          "stateName": "Washington DC",
          "countryCode": "USA",
          "stateCode": "WAS",
          "stateDetails": "XXXXX",
          "stateZone": "YYYYYY"
        },
        {
          "id": 24,
          "stateName": "Some Other States",
          "countryCode": "USA",
          "stateCode": "SOS",
          "stateDetails": "XXXXX",
          "stateZone": "YYYYYY"
        }
      ]
    }
  ],
  "last": false,
  "totalPages": 28,
  "totalElements": 326,
  "size": 12,
  "number": 0,
  "sort": null,
  "numberOfElements": 12,
  "first": true
}
Run Code Online (Sandbox Code Playgroud)

我的完整代码如下:

CountryRepository.java

@Repository
public interface CountryRepository …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate spring-data-jpa spring-projections

18
推荐指数
1
解决办法
1008
查看次数

使用@Query(本机和JPQL)的Spring Data Jpa + Spring Projections为相关实体返回null

我想要实现的是使用 JpaRepository 接口在 Spring Data Jpa 中使用 3 种不同的方法编写相同的查询:

  1. 命名方法策略。
  2. @Query 与 JPQL。
  3. @Query 原生 SQL。

在这里,您可以看到我如何使用我尝试选择的所有关系创建访问实体。

public class Visit {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    long visitId;
    LocalDateTime dateFrom;
    LocalDateTime dateTo;
    @Enumerated(EnumType.STRING)
    VisitStatus status;
    @ManyToOne(fetch = FetchType.EAGER)
    @JsonManagedReference
    Doctor doctor;
    @ManyToOne
    @JsonManagedReference
    Patient patient;
    @ManyToMany
    @JsonManagedReference
    List<Disease> diseases;
    @ManyToMany
    @JsonManagedReference
    List<MedicalService> medicalServices;
    String mainSymptoms;
    String treatment;
    String allergy;
    String addiction;
    String comment;
Run Code Online (Sandbox Code Playgroud)

我正在使用 Project Lombok 我不会复制类上方的所有注释。所以这里是实验。我创建的方法应该在给定的时间间隔内返回特定医生的所有访问。

这是我写的方法:

List<VisitView> findByDoctorIdAndStatusAndDateFromGreaterThanEqualAndDateToLessThanEqual
            (long doctorId, VisitStatus visitStatus, LocalDateTime dateFrom, LocalDateTime dateTo); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data-jpa spring-projections

2
推荐指数
1
解决办法
2135
查看次数