我正在使用Spring MVC框架编写简单的博客Web应用程序。我愿意DTO在我的应用程序中添加图层。
我决定使用ModelMapper框架从Entity对象转换为DTO视图中使用的对象。
我只有一个问题。在我的主页上,我正在显示博客中的帖子列表。在我看来,这只是Post(实体)对象的列表。我想更改它以将PostDTO对象列表传递给我的视图。有没有什么办法来映射List的Post对象List的PostDTO单方法调用的对象?我当时正在考虑编写将转换该转换器的转换器,但是我不确定这是否是一个好方法。
另外,我还在其他几个地方使用Lists,Entities例如管理面板或页面上每个帖子下方的评论。
我编写了货币转换器程序,它JSON从api.fixer.io、映射对象中读取并创建选定汇率的简单数据集。我的程序运行良好,直到我停止使用Jackson解析和映射对象并将其替换为RestTemplate. 它可以很好地读取基础货币和日期,但不能很好地读取Rates子对象。为什么?
我的代码:
Currency类:
package com.github.gromo13.currencyConverter.model.util;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Currency {
private String base;
private String date;
private Rates rates;
public Currency() {
}
public String getBase() {
return this.base;
}
public void setBase(String base) {
this.base = base;
}
public String getDate() {
return this.date;
}
public void setDate(String date) {
this.date = date;
}
public Rates getRates() {
return this.rates;
}
public void …Run Code Online (Sandbox Code Playgroud)