技术标签: spring boot之mvc注解
package com.boot.springmvc.advice;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
@ControllerAdvice //1
public class ExceptionHandlerAdvice {
@ExceptionHandler(value = Exception.class)//2
public ModelAndView exception(Exception exception, WebRequest request) {
ModelAndView modelAndView = new ModelAndView("error");// error页面
modelAndView.addObject("errorMessage", exception.getMessage());
return modelAndView;
}
@ModelAttribute //3
public void addAttributes(Model model) {
model.addAttribute("msg", "额外信息"); //3
}
@InitBinder //4
public void initBinder(WebDataBinder webDataBinder) {
webDataBinder.setDisallowedFields("id"); //5
}
}
一:ExceptionHandlerAdvice类
4.通过@InitBinder注解定制WebDataBinder。(5.这里表示过滤掉id)
二:抛出异常演示
package com.boot.springmvc.web.ch2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.boot.springmvc.domain.DemoObj;
@Controller
public class AdviceController {
@RequestMapping("/advice")
public String getSomething(@ModelAttribute("msg") String msg,DemoObj obj){//1
System.out.println("//演示@ModelAttribute");
throw new IllegalArgumentException("非常抱歉,参数有误/"+"来自@ModelAttribute:"+ msg);
}
}
三:异常页面展示
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>@ControllerAdvice Demo</title>
</head>
<body>
${errorMessage}
</body>
</html>
结果:
全局的@ModelAttribute,@RequestMapping都可以获取
webDataBinder.setDisallowedFields("id"); //过滤id属性
文章浏览阅读242次,点赞3次,收藏9次。交换机,壳体采用镀锌钢板,结构紧凑,支持八个百兆端口,可配置一至四个百兆光纤端口。两路冗余电源设计,支持4pin可插拔端子,交直流通用,同时提供电源防接保护及过压、欠压保护,极大提升产品工作的稳定性。2.支持两路冗余电源设计,4pin可插拔端子,支持12~36V宽电压输入,交直流通用,同时提供电源防反接保护及过压、欠压保护,极大提升产品工作的稳定性。4.-40℃~75℃工作温度,-40~85℃存储温度,在极端气象条件下也能安全运行。8.支持IEEE802.3,IEEE802.3u,IEEE802.3x。
文章浏览阅读946次。Hi,我是阿昌,今天教你如何使用通义灵码。_通义灵码
文章浏览阅读2.3w次。我们在开发或编译旧版本NDK项目时,需要使用一些老版本的NDK,在这里提供了旧版NDK的列表及下载链接_ndk 老颁布
文章浏览阅读2.8k次。本来想获取气体放电管的Spice模型,但是找了一圈无果,从littelfuse上找到了半导体放电管P0640SCLRP的Spice模型,使用Cadence对该元件进行仿真,本文仅记录步骤,目的在于对放电管有个感性认识。图1P0640SCLRP参数(绿色背景部分)图2P0640SCLRP I-V曲线Vs@100V/us(转折电压)为77V,Vdrm(峰值闭态电压)为58V,V..._spice模型参数解析
文章浏览阅读165次。一、Java11时代Java 的版本发布周期变更为每六个月一次 , 每半年发布一个大版本,每个季度发布一个中间特性版本,Java 9 和 Java 10 这两个被称为“功能性的版本”,两者均只提供半年的技术支持,Java 11 不仅提供了长期支持服务,还将作为 Java 平台的参考实现。Oracle 直到2023年9月都会为 Java 11 提供技术支持,而补丁和安全警告等扩展支持将持续到2026..._oraclejdk是不是比openjdk所支持api功能的更多
文章浏览阅读45次。# CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client. Y..._redhat6.4yum安装出错
文章浏览阅读275次。1 import java.io.File;23 import java.io.IOException;45 import java.util.Locale;6789 import jxl.CellView;1011 import jxl.Workbook;1213 import jxl.WorkbookSettings;1415 import jxl.format.UnderlineStyle;..._android excel生成读取类
文章浏览阅读4.3w次,点赞16次,收藏126次。1、去微软官网下载完成ISO镜像,最好不要在线安装,打开官方链接 https://www.visualstudio.com/zh-cn/downloads/download-visual-studio-vs.aspx按下图操作:2、用虚拟光驱加载,或者直接右键解压。在安装前,先安装两个证书。亲测,安装后,减少了很多“安装包损坏或丢失”的现象。两证书下载地址链接: https:/..._vs2015离线版csdn
文章浏览阅读2k次,点赞4次,收藏3次。目前 postcss-pxtorem 版本最高6.0.0,报这个错是因为插件版本太高,降成5.1.1可解决这个报错解决方法:分两步1.执行npm uninstall post-pxtorem2.执行npm i [email protected]_error: postcss plugin postcss-import requires postcss 8.
文章浏览阅读787次。Linux-ARM开发_linux arm开发
文章浏览阅读1.1k次。首先我们要先了解下ipad协议是什么 ,ipad协议又叫微信协议 是基于微信IPad协议的智能控制系统帮助企业快速连接客户,创造营销氛围,实现自动获客、自动传播、自动转化、智能营销等分布式营销服务。通过API 实现 个性化微信功能 (例:营销系统、云发单助手、社群小助手、客服系统、机器人等),微信个人号二次开发,基于API开发可以有很多功能模块用来自动管理微信消息。可开发的功能包括但不限于:好友管理:添加好友、删除好友、修改备注、创建标签、获取好友列表、搜索好友信息消息管理:发文本、图片消息、名片消_pad版微信 机器人
文章浏览阅读579次。软件管家出错的情况下安装keil51.按照管家的步骤出错了新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入1...._可以从联想软件管家下载keil吗