当前位置: 首页 > news >正文

新网站怎么做才能让搜狗收录《学做网站论坛》视频下载

新网站怎么做才能让搜狗收录,《学做网站论坛》视频下载,送菜上门网站app如何做,成都网站开发的公司自定义注解类编写的一些规则:1. Annotation型定义为interface, 所有的Annotation会自动继承java.lang.Annotation这一接口,并且不能再去继承别的类或是接口.2. 参数成员只能用public或默认(default)这两个访问权修饰3. 参数成员只能用基本类型byte,short,char,int,long,float,d…自定义注解类编写的一些规则:1. Annotation型定义为interface, 所有的Annotation会自动继承java.lang.Annotation这一接口,并且不能再去继承别的类或是接口.2. 参数成员只能用public或默认(default)这两个访问权修饰3. 参数成员只能用基本类型byte,short,char,int,long,float,double,boolean八种基本数据类型和String、Enum、Class、annotations等数据类型,以及这一些类型的数组.4. 要获取类方法和字段的注解信息必须通过Java的反射技术来获取 Annotation对象,因为你除此之外没有别的获取注解对象的方法5. 注解也可以没有定义成员, 不过这样注解就没啥用了自定义注解类时, 可以指定目标 (类、方法、字段, 构造函数等) , 注解的生命周期(运行时,class文件或者源码中有效), 是否将注解包含在javadoc中及是否允许子类继承父类中的注解, 具体如下:1. Target 表示该注解目标,可能的 ElemenetType 参数包括:ElemenetType.CONSTRUCTOR 构造器声明ElemenetType.FIELD 域声明(包括 enum 实例)ElemenetType.LOCAL_VARIABLE 局部变量声明ElemenetType.METHOD 方法声明ElemenetType.PACKAGE 包声明ElemenetType.PARAMETER 参数声明ElemenetType.TYPE 类接口(包括注解类型)或enum声明2. Retention 表示该注解的生命周期,可选的 RetentionPolicy 参数包括RetentionPolicy.SOURCE 注解将被编译器丢弃RetentionPolicy.CLASS 注解在class文件中可用但会被VM丢弃RetentionPolicy.RUNTIME VM将在运行期也保留注释因此可以通过反射机制读取注解的信息3. Documented 指示将此注解包含在 javadoc 中4.  Inherited 指示允许子类继承父类中的注解类注解的定义importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/*** 注解类* author Owner*/Retention(RetentionPolicy.RUNTIME)Target(ElementType.TYPE)publicinterfaceMyClassAnnotation {String uri();String desc();}构造方法注解定义importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/*** 构造方法注解* author Owner**/Retention(RetentionPolicy.RUNTIME)Target(ElementType.CONSTRUCTOR)publicinterfaceMyConstructorAnnotation {String uri();String desc();}方法注解定义importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/*** 我的方法注解* author Owner**/Retention(RetentionPolicy.RUNTIME)Target(ElementType.METHOD)publicinterfaceMyMethodAnnotation {String uri();String desc();}字段注解定义importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/*** 字段注解定义* author Owner**/Retention(RetentionPolicy.RUNTIME)Target(ElementType.FIELD)publicinterfaceMyFieldAnnotation {String uri();String desc();}最后定义一个测试类importjava.lang.reflect.Constructor;importjava.lang.reflect.Field;importjava.lang.reflect.Method;MyClassAnnotation(descThe class name, uricom.annotation.MySample)publicclassMyTest {MyFieldAnnotation(descThe class field, uricom.annotation.MySample#id)privateintid;MyConstructorAnnotation(descThe class constructor, uricom.annotation.MySample#MySample)publicMyTest(){}publicintgetId() {returnid;}MyMethodAnnotation(descThe class method, uricom.annotation.MySample#setId)publicvoidsetId(intid) {this.id  id;}publicstaticvoidmain(String[] args)throwsException {Class clazz  MyTest.class;//得到类注解MyClassAnnotation myClassAnnotation  clazz.getAnnotation(MyClassAnnotation.class);System.out.println(myClassAnnotation.desc() myClassAnnotation.uri());//得到构造方法注解Constructor cons  clazz.getConstructor(newClass[]{});MyConstructorAnnotation myConstructorAnnotation  cons.getAnnotation(MyConstructorAnnotation.class);System.out.println(myConstructorAnnotation.desc() myConstructorAnnotation.uri());//获取方法注解Method method  clazz.getMethod(setId,newClass[]{int.class});MyMethodAnnotation myMethodAnnotation  method.getAnnotation(MyMethodAnnotation.class);System.out.println(myMethodAnnotation.desc() myMethodAnnotation.uri());//获取字段注解Field field  clazz.getDeclaredField(id);MyFieldAnnotation myFieldAnnotation  field.getAnnotation(MyFieldAnnotation.class);System.out.println(myFieldAnnotation.desc() myFieldAnnotation.uri() );}}输出The class name com.annotation.MySampleThe class constructor com.annotation.MySample#MySampleThe class method com.annotation.MySample#setIdThe class field com.annotation.MySample#id好了上面是基本学习我们在实际的项目中用在什么地方呢我想我们都做过关于细粒度权限拦截的问题在Struts2中可以根据登录用户所具有的的权限进行任Retention(RetentionPolicy.RUNTIME)//代表Permission注解保留在的阶段Target(ElementType.METHOD)//标注在方法上面publicinterfacePermission {/** 模块 */String module();/** 权限值 */String privilege();}比如有一个部门actionDepartment.action,有一个方法public String departmentlistUI(){}可以这样定义方法Permission(moduledepartment,privilegeview)publicString departmentlistUI(){}然后自定定义一个权限拦截器PrivilegeInterceptor.java并在struts.xml中注册在实现interceptor接口后实现方法public String intercept(ActionInvocation invocation) throws Exception {}在这里调用任一个action方法都会经过该拦截方法通过invocation可以获取当前调用的action的名字以及调用的action的哪个方法通过这段代码可以获取action名字和方法名String  actionNameinvocation.getProxy().getActionName();String  methodNameinvocation.getProxy().getMethod();System.out.println(拦截到action的名字actionName方法名methodName);然后通过反射技术获取该方法上的自定义权限注解获取当前登录的用户(从session中)遍历当前用户的所拥有的权限组并且遍历任一个权限组下的所有的权限看是否包括该方法上注解所需的权限。这样就可以完成细粒度的action方法权限拦截了。这只是个大体的思路下面看一下拦截器的具体实现该功能的代码privatebooleanvalidate(ActionInvocation invocation)throwsSecurityException, NoSuchMethodException {String  methodNameinvocation.getProxy().getMethod();Method currentMethod  invocation.getAction().getClass().getMethod(methodName);if(currentMethod !null currentMethod.isAnnotationPresent(Permission.class)){//得到方法上的注解Permission permission  currentMethod.getAnnotation(Permission.class);//该方法上的所需要的权限SystemPrivilege methodPrivilege  newSystemPrivilege(newSystemPrivilegePK(permission.module(), permission.privilege()));//得到当前登录的用户Employee e  (Employee) ActionContext.getContext().getSession().get(loginUser);//遍历当前用户下的所有的权限组for(PrivilegeGroup group : e.getGroups()){//如果该权限组下包含要访问该方法所需要的权限就放行if(group.getPrivileges().contains(methodPrivilege)){returntrue;}}//说明遍历的该用户所有的权限组没有发现该权限说明没有该权限returnfalse;}//没有标注注解表示谁都可以调用该方法returntrue;}
http://www.pierceye.com/news/870647/

相关文章:

  • 书店网站开发目的和意义深圳网建公司
  • 餐饮网站方案wordpress 微论坛主题
  • 上海建筑网站设计多用户商城数据库设计
  • 网站做301将重定向到新域名深圳seo优化外包公司
  • 做视频导航网站有哪些天津西青区离哪个火车站近
  • 福州网站建设技术支持公司培训课程有哪些
  • 保定网站制作域名注册商查询
  • 医院网站建设公司价格低天津建设工程信息网 塘沽一中
  • 建设机械网站案例建国外网站需要多少钱
  • 比特币简易网站开发电商网站大全
  • 秀屿区建设局网站巨量广告投放平台
  • 合肥网站设计哪家公司好北京国贸网站建设公司
  • 帮人做网站怎么收费制作链接的app的软件有哪些
  • 商贸行业网站建设公司yoast wordpress seo
  • 上小学网站建设WordPress底部添加运行时间
  • 学校网站信息化建设工作心得网络营销现状分析
  • 藁城专业网站建设班级同学录网站建设
  • 北京手机网站开发公司wordpress用户列表
  • 上海 企业网站制成都营销型网站建设熊掌号
  • 无锡网站优化哪家好北京注册公司地址可以是住宅吗
  • 中国十大热门网站深圳哪做网站
  • 木渎网站建设聚美优品网站建设情况
  • 企业形象网站用什么语言开发网站优化要做哪些工作
  • 中国建设银行官网站电话号码wordpress关键词排名
  • 南通网站建设机构博物馆网站建设的根本意义
  • 食品企业网站建设中信建设有限责任公司陈晓佳
  • 中国网站服务器哪个好店名注册查询
  • 网站设计制作案例软件定制开发的发展前景
  • 中国联通网站备案小程序是什么原理
  • 企业网站建设御彩云dz做电影网站