Spring Data-在投影中使用属性值

我有Spring Data Rest Application,我在其中创建了这样的投影

@Projection(name = "UserWithAvatar",types = { User.class })
public interface UserWithAvatar {
    String getName();
    String getEmail();

    @Value("${app.url}/pictures/#{target.imageId}")
    String getavatar();
}

无效的部分是getavatar,它会生成一个用于查看图片的网址。
但是,此${app.url}在投影内部不起作用。
如何在其中添加这个application.properties值?

wuya790 回答:Spring Data-在投影中使用属性值

@environment.getProperty('app.url')块中使用#{}。它可以在Spring Boot 2.3.0上运行,我不确定较旧的版本。

示例:

@Value("#{target.pictureUrl ?: @environment.getProperty('app.url') + 'static/default-avatar.png'}")
String getAvatarUrl();
本文链接:https://www.f2er.com/3095190.html

大家都在问