YMPオンラインマニュアル
/ 高級特性—異常錯誤處理器
高級特性—異常錯誤處理器
WebMVC模塊為開發(fā)者提供了一個IWebErrorProcessor接口,允許針對異常、驗證結果和約定模式的URL解析邏輯實現(xiàn)自定義擴展;
通過下面的參數(shù)配置即可:
ymp.configs.webmvc.error_processor_class=net.ymate.framework.webmvc.WebErrorProcessor
示例代碼:
public class WebErrorProcessor implements IWebErrorProcessor { /** * 異常時將執(zhí)行事件回調 * * @param owner 所屬YMP框架管理器實例 * @param e 異常對象 */ public void onError(IWebMvc owner, Throwable e) { // ...你的代碼邏輯 } /** * @param owner 所屬YMP框架管理器實例 * @param results 驗證器執(zhí)行結果集合 * @return 處理結果數(shù)據(jù)并返回視圖對象,若返回null則由框架默認處理 */ public IView onValidation(IWebMvc owner, Map<String, ValidateResult> results) { // ...你的代碼邏輯 return View.nullView(); } /** * 自定義處理URL請求過程 * * @param owner 所屬YMP框架管理器實例 * @param requestContext 請求上下文 * @return 可用視圖對象,若為空則采用系統(tǒng)默認 * @throws Exception 可能產(chǎn)生的異常 */ public IView onConvention(IWebMvc owner, IRequestContext requestContext) throws Exception { // ...你的代碼邏輯 return View.nullView(); } }