Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 模型映射器计算_Java_Modelmapper - Fatal编程技术网

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;
}