问题描述
如题怎么的啊?搞了一天。。其实就是想实现个权限拦截。。以前没做过权限拦截这块。。现在必须要弄。。老火啊,,求助各位大侠了。。在线等答案啊
解决方案
解决方案二:
packagecom.zz.action.admin;importorg.aspectj.lang.ProceedingJoinPoint;importorg.aspectj.lang.annotation.Around;importorg.aspectj.lang.annotation.Aspect;importorg.aspectj.lang.annotation.Pointcut;importorg.springframework.stereotype.Component;@Aspect@ComponentpublicclassInterceptor{@Pointcut("execution(Stringcom.zz.action.admin..*())"+"&&!execution(Stringcom.zz.action.admin..get*())"+"&&!execution(Stringcom.zz.action.admin..set*())")publicvoidmyMethod(){}@Around("myMethod()")publicObjectinterceptor(ProceedingJoinPointpjp)throwsThrowable{System.out.println("拦截到"+pjp.getSignature().getName());returnpjp.proceed();}}
解决方案三:
packagecom.zz.action.admin;importjava.io.Serializable;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.List;importjavax.annotation.Resource;importcom.opensymphony.xwork2.ActionSupport;importcom.zz.entity.Product;importcom.zz.entity.ProductCategory;importcom.zz.service.ProductCategoryService;importcom.zz.service.ProductService;importcom.zz.util.FileUploadUtil;importcom.zz.util.Pager;/***后台Action类-商品**@authorsuperzh**/publicclassProductActionextendsActionSupportimplementsSerializable{privatestaticfinallongserialVersionUID=-4433964283757192334L;privateFileUploadUtilfileUploadUtil;privateStringid;privatePagerpager;privateProductproduct;privateList<Product>productList;privateProductCategoryServiceproductCategoryService;privateProductServiceproductService;//添加publicStringadd(){return"add";}//删除publicStringdelete()throwsException{productService.delete(id);returnSUCCESS;}/*publicStringdelete()throwsException{for(Stringid:ids){Productproduct=productService.load(id);Set<OrderItem>orderItemSet=product.getOrderItemSet();for(OrderItemorderItem:orderItemSet){if(orderItem.getOrder().getOrderStatus()!=OrderStatus.completed&&orderItem.getOrder().getOrderStatus()!=OrderStatus.invalid){returnajaxJsonErrorMessage("商品["+product.getName()+"]订单处理未完成,删除失败!");}}}productService.delete(ids);flushCache();returnajaxJsonSuccessMessage("删除成功!");}*///编辑publicStringedit(){product=productService.load(id);return"update";}//获取商品分类树publicList<ProductCategory>getProductCategoryTreeList(){returnproductCategoryService.getProductCategoryTreeList();}//列表@Permission(privilegeValue="商品列表")publicStringlist(){if(pager.getPageNumber()>pager.getPageCount()){pager.setPageNumber(pager.getPageCount());}if(id!=null){ProductCategoryproductCategory=productCategoryService.load(id);pager=productService.getProductPager(productCategory,pager);}else{pager=productService.findByPager(pager);}return"list";}//load一个商品publicStringload(){product=productService.load(id);return"detail";}//保存商品publicStringsave()throwsException{if(product.getPrice().longValue()<0){addActionMessage("销售价不允许小于0");returnERROR;}if(product.getMarketPrice().longValue()<0){addActionMessage("市场价不允许小于0");returnERROR;}if(product.getProductCategory().getId()==null||product.getProductCategory().getId().length()<=0){addActionMessage("请先选择分类");returnERROR;}try{if(fileUploadUtil.getMyFile()!=null){fileUploadUtil.ProcessFileUpload();product.setProductImageSrc(fileUploadUtil.getImagesrc());}}catch(Exceptione){System.out.print("没有上传图片");}SimpleDateFormatsdf=newSimpleDateFormat("yyyyMMddHHmmss");product.setCreateDate(newDate());if(product.getDescription().length()>200){product.setLittleDes(product.getDescription().substring(0,200)+"...");}else{product.setLittleDes(product.getDescription());}product.setProductSn("SN"+sdf.format(newDate()));product.setFreezeStore(0);productService.save(product);returnSUCCESS;}//更新publicStringupdate()throwsException{ProductproductIn=productService.load(id);if(product.getPrice().longValue()<0){addActionError("销售价不允许小于0");returnERROR;}if(product.getMarketPrice().longValue()<0){addActionError("市场价不允许小于0");returnERROR;}//如果上传了新的商品图片就删除原有图片并设置商品的新图片try{if(fileUploadUtil.getMyFile()!=null){fileUploadUtil.ProcessFileUpload();productService.updateImage(product.getId());product.setProductImageSrc(fileUploadUtil.getImagesrc());}}catch(Exceptione){product.setProductImageSrc(productIn.getProductImageSrc());System.out.println("么有上传图片");}if(product.getStore()==0){product.setFreezeStore(0);}/*product.setProductSn(productIn.getProductSn());product.setCartItemSet(productIn.getCartItemSet());product.setLittleDes(productIn.getLittleDes());product.setFreezeStore(productIn.getFreezeStore());product.setCreateDate(productIn.getCreateDate());*/productService.update(product);returnSUCCESS;}@ResourcepublicvoidsetProductCategoryService(ProductCategoryServiceproductCategoryService){this.productCategoryService=productCategoryService;}publicProductCategoryServicegetProductCategoryService(){returnproductCategoryService;}@ResourcepublicvoidsetProductService(ProductServiceproductService){this.productService=productService;}publicProductServicegetProductService(){returnproductService;}publicProductgetProduct(){returnproduct;}publicvoidsetProduct(Productproduct){this.product=product;}publicStringgetId(){returnid;}publicvoidsetId(Stringid){this.id=id;}@ResourcepublicvoidsetPager(Pagerpager){this.pager=pager;}publicPagergetPager(){returnpager;}publicFileUploadUtilgetFileUploadUtil(){returnfileUploadUtil;}publicvoidsetFileUploadUtil(FileUploadUtilfileUploadUtil){this.fileUploadUtil=fileUploadUtil;}publicvoidsetProductList(List<Product>productList){this.productList=productList;}publicList<Product>getProductList(){returnproductList;}}
解决方案四:
没有用aop拦截之前一切正常。。但是加上之后就会报空指针异常。。。、我测试了一下。是service没被注入。。引起的空指针异常。。。这是怎么的啊
解决方案五:
请问这个问题后来怎么解决的?我也碰到了这个问题
解决方案六:
把<aop:aspectj-autoproxy/>放到第一个配置文件里,就是默认的那个,就可以。