Java 模型映射器计算
我正在尝试使用Java 模型映射器计算,java,modelmapper,Java,Modelmapper,我正在尝试使用ModelMapper在映射过程中计算属性。这是可能的,因为它没有像我预期的那样工作 PropertyMap<com.fmg.myfluent.domain.Quote, ClientQuote> personMap = new PropertyMap<com.fmg.myfluent.domain.Quote, ClientQuote>() { protected void configure() { m
ModelMapper
在映射过程中计算属性。这是可能的,因为它没有像我预期的那样工作
PropertyMap<com.fmg.myfluent.domain.Quote, ClientQuote> personMap = new
PropertyMap<com.fmg.myfluent.domain.Quote, ClientQuote>() {
protected void configure() {
map().setTotalLoan(source.getTotalPayable());
// monthlyRate NOT Working!
map().setMonthlyRate((source.getAnnualRate()/12));
}
};
实际:
年利率=12,月利率:12
您需要添加一个手动转换器来转换ModelMapper中的值
Converter<Integer, Integer> annualToMonthlyConverter = ctx -> ctx.getSource() == 0 ? 0 : ctx.getSource() / 12;
您需要添加手动转换器来转换
ModelMapper
Converter<Integer, Integer> annualToMonthlyConverter = ctx -> ctx.getSource() == 0 ? 0 : ctx.getSource() / 12;
Thanx Debmalya这就是我要找的。我曾尝试“使用”转换器,但忘记/错过了地图!我很高兴这有帮助。如果您觉得这有帮助,请接受答案。谢谢你,这就是我要找的。我曾尝试“使用”转换器,但忘记/错过了地图!我很高兴这有帮助。如果您觉得这有帮助,请接受答案。谢谢
PropertyMap<Source, Target> personMap = new
PropertyMap<Source, Target>() {
protected void configure() {
map().setAnnual(source.getAnnual());
using(annualToMonthlyConverter).map(source.getAnnual(), destination.getMonthly());
}
};
public int getMonthly() {
return annual / 12;
}