我有一个用例,我想显示实体的内容,但隐藏某些字段。我的实体如下 -
实体
public class StudentDetail {
@Id
private Long ID;
private String firstName;
private String middleName;
private String lastName;
@JsonFormat(pattern="dd-MMM-yyyy", timezone="IST")
@Temporal(TemporalType.DATE)
private Date dateOfBirth;
}
它还具有许多其他属性,我在这里不显示。
存储库 -
@Repository
public interface StudentDetailsRepository extends JpaRepository<StudentDetail, Integer> {
@Query("select d from StudentDetail d where month(d.dateOfBirth) = ?1 ")
List<StudentDetail> getStudentListBasedOnDateOfBirth(int month);
}
服务等级 -
public List<StudentDetail> getStudentBirthdayDetails(int month) {
List<StudentDetail> StudentDetail = StudentDetailsRepository.getStudentListBasedOnDateOfBirth(month);
return StudentDetail;
}
还有一个控制器类,它使用参数调用 Service 类来过滤数据集。month
我想做的是修改存储库类中的查询,并仅包含 、 和 属性。存储库类应隐藏该字段。我意识到以下查询将返回过滤后的项目 -firstnamemiddleNamelastNamedateOfBirth
select d.firstName, d.middleName, d.lastName from StudentDetail d where month(d.dateOfBirth) = ?1
但是,该类的返回类型是 实体类型 学生详细信息 。仅从中选择几个字段将导致错误。所以,我想知道我应该在/ 和类中进行哪些更改(假设只有返回类的类型会更改)?Repositoryreposervicecontroller
九州编程
相关分类