标签:des io 使用 java ar 2014 代码 sp log
1.自定义一个annotation
package com.websystem.util; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * des:自定义使方法跳过拦截的注解 * author: zbl * date: 2014年9月3日 **/ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public abstract @interface RequiredInterceptor{ boolean required() default true; }
package com.websystem.controller; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.view.RedirectView; import com.websystem.model.ManagerModel; import com.websystem.service.ManagerService; import com.websystem.util.AESPlusHelper; import com.websystem.util.Constant; import com.websystem.util.RequiredInterceptor; /** * des: * author: zbl * date: 2014年8月26日 **/ @Controller @SessionAttributes(Constant.Manager) public class ManagerController { @Resource private ManagerService managerServiceImpl; @RequiredInterceptor(required = false) @RequestMapping(value = "manager/login.do",method = RequestMethod.GET) public ModelAndView login(ManagerModel managerModel,ModelMap model){ ManagerModel manager = managerServiceImpl.getManager(managerModel); if(manager!=null){ manager.setPassword(""); model.addAttribute(Constant.Manager, manager); return new ModelAndView(new RedirectView(Constant.MainURL)); }else{ return new ModelAndView(new RedirectView(Constant.LoginURL)); } } @RequiredInterceptor(required = false) @RequestMapping(value = "manager/logout.do",method = RequestMethod.GET) @ResponseBody public Object logout(SessionStatus status){ status.setComplete(); Map<String,Object> map = new HashMap<String,Object>(); map.put(Constant.Success, true); return map; } }
package com.websystem.util; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.stereotype.Component; /** * des: * author: zbl * date: 2014年9月3日 **/ @Component public class SessionInterceptor implements MethodInterceptor { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // TODO Auto-generated method stub RequiredInterceptor requiredInterceptor = AnnotationUtils.findAnnotation(invocation.getMethod(), RequiredInterceptor.class); if(requiredInterceptor!=null){ System.out.println(invocation.getMethod().getName()); //你要做的逻辑代码 } return invocation.proceed(); } }4.添加配置
<context:component-scan base-package="com.websystem.controller,com.websystem.*.impl,com.websystem.util"/> <mvc:annotation-driven/> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list><value>*Controller</value></list> </property> <property name="interceptorNames"> <list><value>sessionInterceptor</value></list> </property> </bean>
标签:des io 使用 java ar 2014 代码 sp log
原文地址:http://blog.csdn.net/heirenheiren/article/details/39030767