高级特性—异常错误处理器
WebMVC模块为开发者提供了一个IWebErrorProcessor接口,允许针对异常、验证结果和约定模式的URL解析逻辑实现自定义扩展;
通过下面的参数配置即可:
ymp.configs.webmvc.error_processor_class=net.ymate.framework.webmvc.WebErrorProcessor
示例代码:
public class WebErrorProcessor implements IWebErrorProcessor {
/**
* 异常时将执行事件回调
*
* @param owner 所属YMP框架管理器实例
* @param e 异常对象
*/
public void onError(IWebMvc owner, Throwable e) {
// ...你的代码逻辑
}
/**
* @param owner 所属YMP框架管理器实例
* @param results 验证器执行结果集合
* @return 处理结果数据并返回视图对象,若返回null则由框架默认处理
*/
public IView onValidation(IWebMvc owner, Map<String, ValidateResult> results) {
// ...你的代码逻辑
return View.nullView();
}
/**
* 自定义处理URL请求过程
*
* @param owner 所属YMP框架管理器实例
* @param requestContext 请求上下文
* @return 可用视图对象,若为空则采用系统默认
* @throws Exception 可能产生的异常
*/
public IView onConvention(IWebMvc owner, IRequestContext requestContext) throws Exception {
// ...你的代码逻辑
return View.nullView();
}
}