shiro框架作为一种特权的开源框架,通过身份验证和授权从具体的业务逻辑分离极大地提高了我们的发展速度,它的易用性使得它越来越受到人们的青睐。上一页ACL架相比,shiro能更easy的实现权限控制,并且作为基于RBAC的权限管理框架通过与shiro标签结合使用。可以让开发者在更加细粒度的层面上进行控制。

举个样例来讲,之前我们使用基于ACL的权限控制大多是控制到连接(这里的连接大家可以简单的觉得是页面。下同)层面,也就是通过给用户授权让这个用户对某些连接拥有权限。这样的情况显然不太适合详细的项目开发,由于在某些情况下。某个用户可能仅仅对某个连接的某个部分有权限。比方这个连接的页面上有增删改查四个button。而当前登录用户对这个页面有查看的权限。可是没有增删改的权限,假设用之前的基于ACL的权限管理。我们手动控制某个button的显示。某些button的不显示是十分麻烦的,shiro通过标签就非常好的攻克了这个问题。shiro不但能细化控制粒度。并且通过加密算法可以更加安全的保证用户password的安全性。以下结合实例介绍一下shiro的详细使用。

1.spring集成shiro

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. version="2.5">
  6. <welcome-file-list>
  7. <welcome-file>login.jsp</welcome-file>
  8. </welcome-file-list>
  9.  
  10. <!-- 载入spring的配置****begin -->
  11. <listener>
  12. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  13. </listener>
  14. <context-param>
  15. <param-name>contextConfigLocation</param-name>
  16. <param-value>classpath*:config/spring/appCtx-*.xml</param-value>
  17. </context-param>
  18. <!-- 载入spring的配置****end -->
  19.  
  20. <!-- 载入Log4j的配置****begin -->
  21. <context-param>
  22. <param-name>log4jConfigLocation</param-name>
  23. <param-value>/WEB-INF/classes/log4j.properties</param-value>
  24. </context-param>
  25. <listener>
  26. <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  27. </listener>
  28. <!-- 载入Log4j的配置****end -->
  29.  
  30. <!--
  31. 解决Hibernate的Session的关闭与开启问题
  32. 功能是用来把一个Hibernate Session和一次完整的请求过程相应的线程相绑定。目的是为了实现"Open Session in View"的模式。
  33.  
  34. 比如: 它同意在事务提交之后延迟载入显示所须要的对象
  35. -->
  36. <filter>
  37. <filter-name>openSessionInViewFilter</filter-name>
  38. <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
  39. </filter>
  40. <filter-mapping>
  41. <filter-name>openSessionInViewFilter</filter-name>
  42. <url-pattern>/*</url-pattern>
  43. </filter-mapping>
  44.  
  45. <!-- 载入shiro的配置*********begin***** -->
  46. <filter>
  47. <filter-name>shiroFilter</filter-name>
  48. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  49. <init-param>
  50. <param-name>targetFilterLifecycle</param-name>
  51. <param-value>true</param-value>
  52. </init-param>
  53. </filter>
  54. <filter-mapping>
  55. <filter-name>shiroFilter</filter-name>
  56. <url-pattern>/*</url-pattern>
  57. </filter-mapping>
  58. <!-- 载入shiro的配置*********end***** -->
  59.  
  60. <!-- 载入struts2的配置******begin****** -->
  61. <filter>
  62. <filter-name>struts2</filter-name>
  63. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  64. </filter>
  65. <filter-mapping>
  66. <filter-name>struts2</filter-name>
  67. <url-pattern>/*</url-pattern>
  68. </filter-mapping>
  69. <!-- 载入struts2的配置*******end********* -->
  70. </web-app>

2.shiro的主要配置文件shiro.xml文件:

  1. <?xml version="1.0" encoding="UTF-8"?
  2.  
  3. >
  4. <beans xmlns="http://www.springframework.org/schema/beans"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xmlns:util="http://www.springframework.org/schema/util"
  9. xmlns:context="http://www.springframework.org/schema/context"
  10. xsi:schemaLocation="
  11. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  12. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  13. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  14. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  15. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  16. ">
  17. <!-- 自己主动扫描载入springbean*****begin********* -->
  18. <context:annotation-config />
  19. <context:component-scan base-package="com" />
  20. <!-- 自己主动扫描载入springbean*****end********* -->
  21.  
  22. <!-- 载入springproperties文件*****begin********* -->
  23. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  24. <property name="fileEncoding" value="utf-8" />
  25. <property name="locations">
  26. <list>
  27. <value>classpath*:/config/properties/deploy.properties</value>
  28. </list>
  29. </property>
  30. </bean>
  31. <!-- 载入springproperties文件*****end******** -->
  32.  
  33. <!-- 载入数据库的相关连接****************begin********** -->
  34. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  35. <!-- 基本属性 urluserpassword -->
  36. <property name="url" value="${datasource.url}" />
  37. <property name="username" value="${datasource.username}" />
  38. <property name="password" value="${datasource.password}" />
  39. <property name="driverClassName" value="${datasource.driverClassName}"></property>
  40.  
  41. <!-- 配置初始化大小、最小、最大 -->
  42. <property name="initialSize" value="${druid.initialPoolSize}" />
  43. <property name="minIdle" value="${druid.minPoolSize}" />
  44. <property name="maxActive" value="${druid.maxPoolSize}" />
  45.  
  46. <!-- 配置获取连接等待超时的时间 -->
  47. <property name="maxWait" value="${druid.maxWait}" />
  48.  
  49. <!-- 配置间隔多久才进行一次检測。检測须要关闭的空暇连接。单位是毫秒 -->
  50. <property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
  51.  
  52. <!-- 配置一个连接在池中最小生存的时间。单位是毫秒 -->
  53. <property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
  54.  
  55. <property name="validationQuery" value="${druid.validationQuery}" />
  56. <property name="testWhileIdle" value="${druid.testWhileIdle}" />
  57. <property name="testOnBorrow" value="${druid.testOnBorrow}" />
  58. <property name="testOnReturn" value="${druid.testOnReturn}" />
  59.  
  60. <!-- 打开PSCache,而且指定每一个连接上PSCache的大小 -->
  61. <property name="poolPreparedStatements" value="${druid.poolPreparedStatements}" />
  62. <property name="maxPoolPreparedStatementPerConnectionSize" value="${druid.maxPoolPreparedStatementPerConnectionSize}" />
  63.  
  64. <!-- 配置监控统计拦截的filters,如需防御SQL注入则增加wall -->
  65. <property name="filters" value="${druid.filters}" />
  66. <property name="connectionProperties" value="${druid.connectionProperties}" />
  67. </bean>
  68.  
  69. <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  70. <property name="dataSource" ref="dataSource"/>
  71. <!-- <property name="packagesToScan">-->
  72. <!-- <list>-->
  73. <!-- <value>com.wenc.*.po</value>-->
  74. <!-- </list>-->
  75. <!-- </property>-->
  76. <property name="packagesToScan"
  77. value="com.wenc.core.po" />
  78. <!-- <property name="mappingLocations"> 此处加入Java类和数据库表的映射关系|mappingLocations取代mappingResources -->
  79. <!-- <list>-->
  80. <!-- <value>classpath:/com/wec/po/**/*.hbm.xml</value> -->
  81. <!-- </list>-->
  82. <!-- </property>-->
  83. <property name="hibernateProperties">
  84. <props>
  85. <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
  86. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  87. <prop key="hibernate.hbm2ddl.auto">update</prop>
  88. <prop key="hibernate.show_sql">true</prop>
  89. <prop key="hibernate.format_sql">true</prop>
  90. <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
  91. <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
  92. <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
  93. <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
  94. <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>
  95. <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
  96. <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
  97. <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
  98. <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop>
  99. <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
  100. </props>
  101. </property>
  102. </bean>
  103. <!-- 载入数据库的相关连接****************end********** -->
  104.  
  105. <!-- spring的事务控制****************begin********** -->
  106. <!-- 开启AOP监听 仅仅对当前配置文件有效 -->
  107. <aop:aspectj-autoproxy expose-proxy="true"/>
  108.  
  109. <!-- 开启注解事务 仅仅对当前配置文件有效 -->
  110. <tx:annotation-driven transaction-manager="transactionManager"/>
  111.  
  112. <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  113. <property name="sessionFactory">
  114. <ref bean="sessionFactory" />
  115. </property>
  116. <property name="globalRollbackOnParticipationFailure" value="true" />
  117. </bean>
  118.  
  119. <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
  120. <tx:attributes>
  121. <tx:method name="do*" propagation="REQUIRED" />
  122. <tx:method name="save*" propagation="REQUIRED" />
  123. <tx:method name="up*" propagation="REQUIRED" />
  124. <tx:method name="del*" propagation="REQUIRED" />
  125. <tx:method name="sear*" propagation="REQUIRED" read-only="true" />
  126. <tx:method name="search*" propagation="REQUIRED" read-only="true" />
  127. <tx:method name="find*" propagation="REQUIRED" read-only="true" />
  128. <tx:method name="get*" propagation="REQUIRED" read-only="true" />
  129. </tx:attributes>
  130. </tx:advice>
  131. <aop:config expose-proxy="true" proxy-target-class="true">
  132. <aop:pointcut id="txPointcut" expression="execution(* com.wenc.*.service.*.*(..))" />
  133. <aop:advisor advice-ref="transactionAdvice" pointcut-ref="txPointcut" order="1"/>
  134. </aop:config>
  135. <!-- spring的事务控制****************end********** -->
  136.  
  137. <!-- shiro的配置*************************begin********** -->
  138. <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
  139. <!-- 自己定义的realm -->
  140. <property name="realm" ref="sampleRealmService"/>
  141. </bean>
  142.  
  143. <!-- 保证实现了Shiro内部lifecycle函数的bean运行 -->
  144. <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
  145.  
  146. <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  147. <property name="securityManager" ref="securityManager"/>
  148. <!-- 登陆页面的连接 -->
  149. <property name="loginUrl" value="/login.jsp"/>
  150. <!-- 身份验证后跳转的连接 -->
  151. <property name="successUrl" value="/loginAction.action"/>
  152. <property name="unauthorizedUrl" value="/unauthorized.jsp"/>
  153. <property name="filters">
  154. <util:map>
  155. <entry key="authc">
  156. <bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter"/>
  157. </entry>
  158. </util:map>
  159. </property>
  160. <!-- 指定过滤器
  161. Anon:不指定过滤器,不错是这个过滤器是空的。什么都没做,跟没有一样。
  162. Authc:验证,这些页面必须验证后才干訪问,也就是我们说的登录后才干訪问。
  163.  
  164. 这里还有其它的过滤器,我没用。比方说授权
  165. -->
  166. <property name="filterChainDefinitions">
  167. <value>
  168. /loginAction.action=anon
  169. /** = authc
  170. </value>
  171. </property>
  172. </bean>
  173. <!-- shiro的配置*************************end********** -->
  174. </beans>

3.基本的实现类有三个各自是PersonAction,UserPermissionInterceptor,SampleRealmService,这三个之间的相互协作完毕了shiro的整个认证和授权过程。以下我们来看各个类的作用:

  1. package com.wenc.test.service.web;
  2.  
  3. @Controller
  4. public class PersonAction extends BaseAction implements ModelDriven<User> {
  5.  
  6. private static Logger logger =Logger.getLogger(SampleRealmService.class);
  7.  
  8. @Autowired
  9. private PersonService personService;
  10.  
  11. public String login()throws Exception{
  12. //对用户输入的password进行MD5加密
  13. String newPassword = CipherUtil.MD5Encode(info.getPassword());
  14. logger.info(info.getUsername()+"="+info.getPassword());
  15. Subject currentUser = SecurityUtils.getSubject();
  16.  
  17. UsernamePasswordToken token = new UsernamePasswordToken( info.getUsername(), newPassword);
  18. //token.setRememberMe(true); //是否记住我
  19. try {
  20. /**currentUser.login(token) 提交申请,验证能不能通过,也就是交给shiro。
  21.  
  22. 这里会回调reaml(或自己定义的realm)里的一个方法
  23. protected AuthenticationInfo doGetAuthenticationInfo() */
  24. currentUser.login(token);
  25. } catch (AuthenticationException e) { //验证身份失败
  26. logger.info("验证登陆客户身份失败!");
  27. this.addActionError("username或password错误,请又一次输入!");
  28. return "fail";
  29. }
  30.  
  31. /**Shiro验证后,跳转到此处,这里推断验证是否通过 */
  32. if(currentUser.isAuthenticated()){ //验证身份通过
  33. return SUCCESS;
  34. }else{
  35. this.addActionError("username或password错误。请又一次输入!
  36.  
  37. ");
  38. return "fail";
  39. }
  40.  
  41. }
  42.  
  43. }

这个类的login方法是当我们输入username和password之后,点击登录button所运行的方法,因为在数据库中用户的password是密文形式。所以在进行用户身份验证,我们必须以相同的加密方式来加密用户在页面上输入的password,然后将username和加密后的password放入令牌(也就是token中),之后shiro会通过比对token中的username和password是否与数据库中存放的真正的username和password来确定用户是否为合法用户,而这个验证过程是shiro为我们完毕的,当运行currentUser.login(token)方法的时候会触发验证过程,可是通常情况下这个验证过程是通过我们来自己定义完毕的,为此我们必须自己写一个realm类来继承shiro的AuthorizingRealm类并覆盖其AuthenticationInfo
doGetAuthenticationInfo(AuthenticationToken authcToken)方法,来看SampleRealmService类。这个就是继承AuthorizingRealm并覆盖其方法后的类:

  1. package com.wenc.core.service;
  2.  
  3. @Component
  4. public class SampleRealmService extends AuthorizingRealm {
  5.  
  6. private static Logger logger =Logger.getLogger(SampleRealmService.class);
  7. @Autowired
  8. private PersonDAO personDAO;
  9.  
  10. public SampleRealmService() {
  11. logger.info("-------AAA1------------------");
  12. setName("sampleRealmService");
  13. // setCredentialsMatcher(new Sha256CredentialsMatcher());
  14. }
  15.  
  16. /**
  17. * 身份验证
  18. * @param authcToken 登陆Action封装的令牌
  19. */
  20. protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
  21. UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
  22. /**查询相应的用户是否存在*/
  23. User user =personDAO.getUser(token.getUsername(), token.getPassword().toString());
  24. logger.info(user);
  25. if( user != null ) {
  26. return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), getName());
  27. } else {
  28. return null;
  29. }
  30. }
  31. /**
  32. * 授权
  33. * 注意:统一在struts的拦截器中处理,见UserPermissionInterceptor.java
  34. */
  35. protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  36. Integer userId = (Integer) principals.fromRealm(getName()).iterator().next();
  37. logger.info("用户ID:"+userId);
  38. User user = personDAO.getUser(userId);
  39. if( user != null ) {
  40. SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
  41. for( Role role : user.getRoles() ) {
  42. info.addRole(role.getName());
  43. Set<Perms> set= role.getPermissions();
  44. logger.info(set);
  45. for(Perms perm:set){
  46. info.addStringPermission(perm.getActionName());
  47. }
  48. }
  49. return info;
  50. } else {
  51. return null;
  52. }
  53. }
  54.  
  55. }

如同上面介绍的那样运行验证的过程就进入了身份认证方法体中。也就是在这里讲数据库中查询出来的真实的用户信息和token中的用户信息进行比对,当验证成功后跳转至strut.xml中配置的index.jsp页面,截图例如以下:

至此我们完毕了用户身份验证过程,接下来我们介绍授权过程和通过shiro标签来介绍细粒度的权限控制。当我们点击“主页2”这个超链接的时候会被struts.xml文件里定义的拦截器拦截。拦截器UserPermissionInterceptor代码例如以下:

  1. package com.wenc.core.web.interceptor;
  2.  
  3. public class UserPermissionInterceptor extends AbstractInterceptor {
  4.  
  5. private static final long serialVersionUID = -2185920708747626659L;
  6. private static final Log logger = LogFactory.getLog(UserPermissionInterceptor.class);
  7.  
  8. @Override
  9. public String intercept(ActionInvocation invocation) throws Exception {
  10. ActionContext ac = invocation.getInvocationContext();
  11. Map map = ac.getParameters();
  12.  
  13. String actionName = ac.getName();
  14. String methodName = "";
  15. String[] _methodName = (String[]) map.get("method");
  16. if (_methodName != null) {
  17. methodName = _methodName[0];
  18. }
  19. logger.info("actionName:"+actionName+",方法名:"+methodName);
  20.  
  21. Subject currentUser = SecurityUtils.getSubject();
  22. /**推断是否已经授权*/
  23. if(!currentUser.isPermitted(actionName)){
  24. logger.info("没有有权限");
  25. }
  26. return invocation.invoke();
  27. }
  28. }

当点击“主页2”之后会首先被该拦截器拦截。拦截的过程中会将当前请求(即点击“主页2”相应的action)的action名称取出。我们要验证的就是该用户是否享有对该action的权限,运行到currentUser.isPermitted(actionName)方法的时候就触发了shiro的授权认证功能,相同我们也对这种方法进行了重写,进入的是SampleRealmService类中的授权方法AuthorizationInfo
doGetAuthorizationInfo(PrincipalCollection principals)。在这个函数中我们取出了数据库中配置的该用户的权限,并将用户的全部权限增加到info中,然后返回请求页面,当载入请求页面的时候运行到shiro标签的时候会再次触发授权(注意这次将不被拦截),相当于再次从数据库中将该用户的权限载入了一遍,而且放入到info中,然后shiro标签会依据shiro:hasPermission或者是shiro:hasRole进行比对,假设存在则显示,否则不显示。当然shiro标签除了这两种方式外还有非常多种其它的方式,大家能够自行探索。

至此整个shiro身份认证和授权介绍完成。谢谢阅读,请指正。

版权声明:本文博主原创文章,博客,未经同意不得转载。

shiro权限架作战的更多相关文章

  1. 十、 Spring Boot Shiro 权限管理

    使用Shiro之前用在spring MVC中,是通过XML文件进行配置. 将Shiro应用到Spring Boot中,本地已经完成了SpringBoot使用Shiro的实例,将配置方法共享一下. 先简 ...

  2. Spring Boot Shiro 权限管理 【转】

    http://blog.csdn.net/catoop/article/details/50520958 主要用于备忘 本来是打算接着写关于数据库方面,集成MyBatis的,刚好赶上朋友问到Shiro ...

  3. shiro权限管理的框架-入门

    shiro权限管理的框架 1.权限管理的概念 基本上涉及到用户参与的系统都要进行权限管理,权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问而且只能 ...

  4. (39.1) Spring Boot Shiro权限管理【从零开始学Spring Boot】

    (本节提供源代码,在最下面可以下载)距上一个章节过了二个星期了,最近时间也是比较紧,一直没有时间可以写博客,今天难得有点时间,就说说Spring Boot如何集成Shiro吧.这个章节会比较复杂,牵涉 ...

  5. Spring Boot Shiro 权限管理

    Spring Boot Shiro 权限管理 标签: springshiro 2016-01-14 23:44 94587人阅读 评论(60) 收藏 举报 .embody{ padding:10px ...

  6. SpringMVC下的Shiro权限框架的使用

    SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shiro-web.xml Shiro-MyShiro-权限认证,登录认证层 ...

  7. SpringMVC整合Shiro权限框架

    尊重原创:http://blog.csdn.net/donggua3694857/article/details/52157313 最近在学习Shiro,首先非常感谢开涛大神的<跟我学Shiro ...

  8. shiro权限框架(一)

    不知不觉接触shiro安全框架都快三个月了,这中间配合项目开发踩过无数的坑.现在回想总结下,也算是一种积累,一种分享.中间有不够完美的地方或者不好的地方,希望大家指出来能一起交流.在这里谢谢开涛老师的 ...

  9. Shiro入门之一 -------- Shiro权限认证与授权

    一  将Shirojar包导入web项目 二 在web.xml中配置shiro代理过滤器 注意: 该过滤器需要配置在struts2过滤器之前 <!-- 配置Shiro的代理过滤器 -->  ...

随机推荐

  1. 电驴 emule 源代码分析 (1)

    关于电驴emule 的源代码,网上有一个  叫刘刚的人 分析的 非常多,可是假设你仅仅是看别人的分析,自己没有亲身去阅读代码的话,恐怕非常难  剖析整个系统. 关于emule  主要就是 连接 kad ...

  2. 【ASP.NET Web API教程】2.3.7 创建首页

    原文:[ASP.NET Web API教程]2.3.7 创建首页 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容. Part 7: Crea ...

  3. 消息函数一般是私有的,因为不需要程序员显示的调用,但子类如果需要改写这个方法,则改成保护方法Protected

    许多的面向对象程序设计语言都支持对消息的处理.消息处理是一种动态响应客户类发出的请求,它与过程调用不同.过程调用中,客户类必须知道服务类提供了哪些过程,以及每个过程的调用约定,并且在调用时需要明确指出 ...

  4. Android studio导入Eclipse项目,和一些错误的解决

    Android studio导入Eclipse开发的项目步骤如下 如果已经打开Android studio的话就选择你已打开的项目,关闭然后导入 开始导入 导入完成. 2.项目出错 Error:(13 ...

  5. uva 1415 - Gauss Prime(高斯素数)

    题目链接:uva 1415 - Gauss Prime 题目大意:给出一个a,b,表示高斯数a+bi(i=−2‾‾‾√,推断该数是否为高斯素数. 解题思路: a = 0 时.肯定不是高斯素数 a != ...

  6. Delphi中获取Unix时间戳及注意事项(c语言中time()是按格林威治时间计算的,比北京时间多了8小时)

    uses DateUtils;DateTimeToUnix(Now) 可以转换到unix时间,但是注意的是,它得到的时间比c语言中time()得到的时间大了8*60*60这是因为Now是当前时区的时间 ...

  7. crm2011js操作IFRAME和选项集

  8. html浏览器兼容性的 JavaScript语法

    1.      在FireFox中能够使用与HTML节点对象ID属性值同样的JS变量名称.可是IE中不行. 解决的方法:在命名上区分HTML节点对象ID属性值和JS变量 2.      IE不支持JS ...

  9. MVC Json 回报

    /// <summary> /// 获取评论列表 /// </summary> /// <param name="pageIndex">< ...

  10. 极路由1s,固件需要刷入RipOS系统的加40块

    极路由1s,固件需要刷入RipOS系统的加40块,集成wifidog功能,wifi广告路由器的理想选择功能. 经过测试,无线性能稳定,无线可带32个手机客户端. 具体配置: 7620CPU ,主频58 ...