问题描述
如何预防异常,requestParameters.sortBy
是作为字符串(java.lang.NumberFormatException
)传递还是缺少(java.lang.NullPointerException
)?
How to prevent exception,if requestParameters.sortBy
is passed as string (java.lang.NumberFormatException
) or is missing (java.lang.NullPointerException
)?
<view-state id="journeySearch" model="journeyForm">
...
<transition on="sort">
<set name="journeyCriteria.sortBy" value="requestParameters.sortBy" type="int" />
<evaluate expression="bookingService.searchJourneys(journeyCriteria)" result="viewScope.journeys" />
</transition>
</view-state>
推荐答案
requestParameters.sortBy
如果不存在,则为null,但不应抛出NullPointerException
requestParameters.sortBy
will be null if it doesn't exist, but it should not throw a NullPointerException
关于NumberFormatException,您可以使用类似的东西:
about the NumberFormatException, you could use something like that:
<global-transitions>
<transition on-exception="java.lang.NumberFormatException" to=""/>
</global-transitions>
您还可以实现自己的异常处理程序,并将其与<exception-handler bean=""/>
一起使用,您可以在流或状态级别使用它.
you could also implement your own exception-handler and use it with <exception-handler bean=""/>
you can use it at the flow or state level.
这篇关于Spring Web Flow异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!