gpt4 book ai didi

java - Spring:如何在投影中使用SpEL表达式

转载 作者:行者123 更新时间:2023-11-30 10:14:56 25 4
gpt4 key购买 nike

在投影 ScheduledSessionWithDetail 中,我想为此添加一个来自其他链接表的值,我正在使用 SpEL 表达式,但它不起作用,我想通过表达式获得没有返回剩余字段,谁能告诉我哪里错了?

ScheduledSessionWithDetail

@Projection(name="ScheduledSessionWithDetail",types=ScheduleSession.class)
public interface ScheduledSessionWithDetail {

Long getId();

int getStartTime();

int getEndTime();

DayOfWeek getDay();

User getCoach();

@Value("#{scheduleSession.programSchedule.level.colorCode}")
String colorCode();
}

调度 session .java

@Entity
public class ScheduleSession {

@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private Long id;

private int startTime;

private int endTime;

private boolean enabled=true;

@OneToOne
private User coach;

@ManyToOne
private ProgramSchedule programSchedule;

@Enumerated(EnumType.STRING)
private DayOfWeek day;
//getter and setter
}

程序安排

@Entity
public class ProgramSchedule {

@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private Long id;

private String name;

@JoinColumn(name="venue_id")
@ManyToOne
private Venue venue;

@JoinColumn(name="program_id")
@ManyToOne
private Program program;

private boolean enabled=true;

@OneToOne
private Term term;
}

等级

@Entity
public class Level{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

private String level;

private int minimumAge=0;

private int maximumAge=0;

private int duration=0;

private int capacity=0;

private String colorCode;
}

最佳答案

您的 ProgramSchedule 实体似乎没有对 Level 的引用


此外,在处理投影时,您应该使用

#{target.programSchedule.level.colorCode}

而不是 bean/参数名称。这在 Spring 博客中提到 https://spring.io/blog/2014/05/21/what-s-new-in-spring-data-dijkstra并在 https://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections 的末尾简要提及

关于java - Spring:如何在投影中使用SpEL表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50712440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com