【发布时间】:2020-02-18 15:24:07
【问题描述】:
在Spring中其实有一个投影接口。像这样:
public interface DaoObjectProjection{
Integer getTotalAmount();
String getCode();
String getName();
String getLastName();
}
我想把它发送到另一个微服务,我知道不能发送接口,因为如果使用 RestTemplate,代理功能不起作用。出于这个原因,我使用了另一个类似的对象:
public class ObjectWantSend {
private Integer totalAmount;
private String code;
private String name;
private String lastName;
//Getters
//Setters
}
我的问题是否存在将我的投影接口直接解析为该对象的任何方法,或者需要像这样一一设置:
ObjectWantSend.setTotalAmount(DaoObjectProjection.getTotalAmount);
我正在使用带有 Spring 的 Hibernate。
【问题讨论】:
-
代理功能是什么意思?
-
这个Spring Documentation这个引用的段落
The query execution engine creates proxy instances of that interface at runtime for each element returned and forwards calls to the exposed methods to the target object.@AndrewS -
我不明白为什么在 REST 调用中使用该接口不起作用。但是,一般来说,将本地数据访问与其他下游交互分开。有时本地数据结构确实符合下游交互的预期,有时则不匹配。另见:MapStruct
-
好的,谢谢你的回答,如果你想回答问题并给你接受。 @AndrewS
标签: java spring hibernate spring-data