[mvel for java] java中利用mvel实现公式计算 #java #mvel
/**
* mvel 实体类
*/
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class MvelBean {
private Long premium;
private Long rate;
}
/**
* 根据公式计算结果
*
* @param mvelBean
* @param formula
* @return
*/
public Long mvelCal(MvelBean mvelBean, String formula) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("mvelBean", mvelBean);
/** 匹配表达式 */
formula = (String) TemplateRuntime.eval(formula, paramMap);
return (Long) MVEL.eval(formula, paramMap);
}
/**
* 公式实例
*/