SpringMVC拦截Controller方法
来源:互联网 发布:pokemon go挂机软件 编辑:程序博客网 时间:2024/05/21 17:28
spring配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd ">
<!-- 【启用springmvc注解驱动】 --><mvc:annotation-driven />
<!-- 使用cglib代理 --><aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="runAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor"> <property name="advice"> <bean class="com.**.api.web.interceptor.MyInterceptor"></bean> </property> <property name="mappedNames"> <list> <value>getDetails</value><!-- 要拦截的方法,用*号匹配多个 --> </list> </property></bean><!-- 使用ProxyFactoryBean 产生代理对象 --><bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <!-- 注意:如果是Controller,首字母不要小写了 --> <value>MyController</value><!-- 要拦截的bean,可以用*号匹配多个。--> </list> </property> <property name="interceptorNames"> <list> <value>runAdvisor</value> </list> </property></bean>
public class MyInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (条件判断) { JSONObject jsonObject = new JSONObject(); jsonObject.put("error", "失败返回"); return jsonObject; } return methodInvocation.proceed(); }}
阅读全文
0 0
- SpringMVC拦截Controller方法
- SpringMVC Controller异常拦截@ControllerAdvice
- SpringMVC的AOP拦截controller
- spring拦截器 拦截springMVC的controller
- Spring aop拦截springmvc的controller请求方法,添加日志和统计方法执行时间
- 在springMVC中使用AOP拦截controller
- SpringMVC关于AOP拦截controller的注意事项
- SpringMVC关于AOP拦截controller的注意事项
- SpringMVC拦截器中通过反射得到Controller方法注解时ClassCastException解决方案
- Sping AOP用AspectJ注解的方式拦截不到SpringMVC的controller方法?
- spring Aop拦截controller方法
- SpringMVC Controller内部跳转如何被拦截器拦截
- SpringMVC之Controller中多个方法
- SpringMVC一个controller写多个方法
- SpringMVC的Controller方法参数
- springMVC(5) springMVC一个controller写多个方法
- SpringMVC-----4、SpringMVC一个controller写多个方法
- Spring AOP无法拦截Controller中的方法
- 初探React-native (二)
- 点击率预估
- Xcode插件,自动生成Getter,带你飞
- 利用ES6-Promise()方法封装原始jsonp实现跨域请求公用方法(告别使用JQuery封装好的jsonp)
- java RandomAccessFile的使用
- SpringMVC拦截Controller方法
- Golang从入门到精通(四):Golang变量定义和初始化
- 竖向走马灯(支持多行或单行)-------简单实用
- 接入友盟第三方登录与分享,判断应用是否安装
- ajax回顾
- Java定时任务调度工具
- Python format 使用实例
- css 三种样式的优先级问题
- 阿里云Elasticsearch的X-Pack:机器学习、安全保障和可视化