第一、先创建一个自定义类继承Exception类
第二、定义一个异常处理器实现handlerExceptionResolver
第三、在配置文件配置springmvc.xml
<!--自定义的异常的功能的实现 -->
<bean class="cn.itcast.ssm.exception.CustomExceptionResolver"></bean>
第四、测试异常功能的实现
@RequestMapping("/editItem")
public String editItem(Model model,HttpServletRequest request,
@RequestParam(required=true,value="id")Integer id)throws Exception{
Items item = itemsService.findItemsById(id);
if(item==null){
throw new CustomException("找不到商品信息");
}
model.addAttribute("item", item);
//String返回的值代表一个逻辑视图
return "editItem";
}