我正在尝试将一种方法放入速度上下文中:
ctx.put("round", roundServiceTime(serviceTimeRound));
public int roundServiceTime (int serviceTimeRound) {
double sum = serviceTimeRound/60;
this.serviceTimeRound = (int)Math.ceil((double)sum);
return serviceTimeRound;
}
错误行:#set( $val = $round(90))
并出现错误:
Encountered "(" at line 175, column 20.
期待以下之一: ... ... “——”…… “+”... “*”... “/”... “%”... “&&”... “||” ... “<”... “<=”... ”>“... ">= ... “==”... “!=”... ...
问题出在哪里?
最佳答案
再次查看您的代码后,我认为您想将某种“魔术链接”放入您的上下文中,以便您可以简单地调用该方法。但上下文只包含对象。
您可以通过将方法放入实用程序类中来实现您想要的目的:
public class Rounder {
public static final Rounder INSTANCE = new Rounder();
public int roundServiceTime (int serviceTimeRound) {
double sum = serviceTimeRound / 60.0;
return (int)Math.ceil(sum);
}
}
然后您可以将实用程序类的实例放入您的上下文中:
ctx.put("rounder", Rounder.INSTANCE);
并在您的模板中使用它:
$rounder.roundServiceTime($someValue)
关于java - 速度上下文方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16769178/