WH : Stupid !! toString().trim().length() > 0

 

使用变量前先判断一下它有没有内容(因为在 Facebook 里并不是每一个 Post 都有 Comment !!) :

 

${commentsCount.toString().trim().length() > 0 && commentsCount.toInt() == 1}

 

而不是:

 

${commentsCount.toInt() == 1} 这样的用法在 commentsCount 字符串为空时会抛出如下异常 :

 

org.webharvest.exception.ScriptException: Error during script execution: Sourced file: inline evaluation of: ``commentsCount.toInt() == 1;'' : Method Invocation commentsCount.toInt

你可能感兴趣的:(Facebook)