Struts 2知识回顾----拦截器(Intercept)总结
什么是Struts 2拦截器?
从软件构架上来说,拦截器是实现了面向方面编程的组件。它将影响了多个业务对象的公共行为封装到一个个可重用的模块,减少了系统的重复代码,实现功能的高度内聚,确保了业务对象的整洁和纯度。
从Java代码上来说,它就是一个普度的Java对象,它只需要实现一个名为Interceptor的接口。
为什么要使用拦截器?
拦截器消除了动作组件中的横切任务(cross-cutting task)。例如,日志记录是一个典型的横切关注。以前,我们可能需要为每个动作组件准备一些记录日志的代码。虽然这样看上去也没什么错误,但是一个不可 以忽视的事实是——这些用于记录日志的代码并不是动作组件与模型交互的一部分。并且,日志记录是我们想为系统处理的每一个请求完成的管理性任务,它不是一 个动作组件所特有的,而是贯穿了所有动作组件。Struts 2将这个功能放在了更高的层次上,我们可以能把日志记录的代码转移到动作组件之外,从而让动作组件更加简洁清晰。
拦截器组件提供了一个不错的场所,来将不同的横切关注点逻辑分成有层次的、可重用的部件。
拦截器的工作原理?
当框架接收到一个请求的时候,它首先必须决定这个URL映射到哪一个动作组件。这个动作组件的一个实例就会被加入到一个新创建的 ActionInvocation实例中。接着框架咨询声明性架构(XML配置文件或Java注解),以发现哪一些拦截器应该被触发,以及按照什么样的顺 序触发。将这些拦截器的引用添加到ActionInvocation中。除了这些核心元素,ActionInvocation也拥有其他重要的信息 (Servlet请求对象和当前动作组件可用的结果组件列表)。
当ActionInvocation被创建完毕,并且填充了需要的所有对象和信息,就可以被使用了。ActionInvocation公开了一个 invoke()方法,框架通过调用这个方法开始动作的执行。当框架调用了这个方法时,ActionInvocation通过执行拦截器栈中的第一个拦截 器开始这个调用过程。需要注意的是,invoke()并不是总是指向拦截器栈的第一个拦截器,ActionInvocation负责跟踪执行过程达到的状 态,并且把控制交给栈中合适的拦截器(通过调用拦截器的intercept()方法将控制权交给拦截器)。通过递归调用(递 归过程?框架通过第一次调用ActionInvocation对象的invoke()方法开始了这个过程。ActionInvocation通过调用拦截 器的intercept()方法把控制权交给第一个拦截器。重要的是,intercept()方法把ActionInvocation实例作为一个参数。 在拦截器的处理过程中,他会调用ActionInvocation实例参数的invoke()方法来继续调用后续拦截器的递归过程。因此,在通常的执行 中,调用过程向下通过所有拦截器,直到栈中再也没有拦截器时,触发动作。另外,ActionInvocation在内部管理处理状态,因此它总是直到自己 现在处在栈的什么位置。)ActionInvocation的invoke()方法,拦截器栈中后续的拦截器继续执行,最终执行动作。这是 因为每一次invoke()方法被调用时,ActionInvocation都会查询自身的状态,调用接下来的拦截器。在所有拦截器都被调用之 后,invoke()方法会促使动作类执行。
下面看一个简单的例子,演示上面所说的理论:
TestAction

- public class TestAction extends ActionSupport
{
private static final long serialVersionUID = 2753590609366162370L;- @Override
public String execute() throws Exception
{
System.out.println("execute");- return SUCCESS;
}- }

Interceptor1

- public class Intercept1 implements Interceptor
{
private static final long serialVersionUID = 8596224826058233434L;- public void destroy()
{- }
- public void init()
{- }
- public String intercept(ActionInvocation invocation) throws Exception
{
System.out.println("interceptor1 begin");- String result = invocation.invoke();
- System.out.println("interceptor1 end");
- return result;
}- }

Interceptor2

- public class Intercept2 implements Interceptor
{
private static final long serialVersionUID = -1580591331691823185L;- public void destroy()
{- }
- public void init()
{- }
- public String intercept(ActionInvocation invocation) throws Exception
{
System.out.println("interceptor2 begin");- String result = invocation.invoke();
- System.out.println("interceptor2 end");
- return result;
}- }

Interceptor3

- public class Intercept3 implements Interceptor
{
private static final long serialVersionUID = 7081124564804422023L;- public void destroy()
{- }
- public void init()
{- }
- public String intercept(ActionInvocation invocation) throws Exception
{
System.out.println("interceptor3 begin");- String result = invocation.invoke();
- System.out.println("interceptor3 end");
- return result;
}- }

有三个自定以的拦截器,他们只是简单的输出几个字符串,拦截器开始将执行输出 "interceptor'x' begin";拦截器结束时输出" interceptor'x' end";
将他们设置在一个指定的动作上

- 1 <interceptors>
2 <interceptor name="interceptor1" class="com.test.suxiaolei.intercept.Intercept1"></interceptor>
3 <interceptor name="interceptor2" class="com.test.suxiaolei.intercept.Intercept2"></interceptor>
4 <interceptor name="interceptor3" class="com.test.suxiaolei.intercept.Intercept3"></interceptor>
5
6 <interceptor-stack name="myStack">
7 <interceptor-ref name="interceptor1"></interceptor-ref>
8 <interceptor-ref name="interceptor2"></interceptor-ref>
9 <interceptor-ref name="interceptor3"></interceptor-ref>
10 <interceptor-ref name="defaultStack"></interceptor-ref>
11 </interceptor-stack>
12 </interceptors>
13
14 <action name="test" class="com.test.suxiaolei.action.TestAction">
15 <result name="success">/index.jsp</result>
16 <interceptor-ref name="myStack"></interceptor-ref>
17 </action>

提交表单,控制台的输出结果:

- interceptor1 begin
interceptor2 begin
interceptor3 begin
execute
interceptor3 end
interceptor2 end
interceptor1 end

从控制台输出的结果可以看出,在提交数据到框架时,框架调用拦截器的过程,首先框架会根据URL请求创建指定的动作TestAction,将 TestAction的实例和TestAction相关的拦截器引用myStack放入一个新的ActionInvocation对象中(还包含其他信 息),然后框架调用ActionInvocation的invoke()方法,此时开始了拦截器栈调用过程,最开始调用拦截器栈的第一个拦截器也就是 Intercept1,拦截器执行完预处理后,因为intercept()方法接收一个ActionInvocation对象作为参数,在 Intercept1.intercept()方法中继续调用 ActionInvocation对象的invoke()方法将向下继续调用栈中余下的拦截器Intercept2...一直到栈中没有拦截器为止,最后 执行动作组件。在结果被呈现之后,拦截器会按照相反的顺序再触发一遍,使他们可以进行后处理。
拦截器工作原理图:
拦截器触发时能够做些什么?
1. 做一些预处理。在这个阶段拦截器可以用来准备、过滤、改变或者操作任何可以访问的重要数据。这些数据包括所有与当前请求相关的关键对象和数据,也包括动作。
2. 通过调用invoke()方法将控制转移给后续的拦截器,直到动作。或者通过返回一个控制字符串中断执行。在这个阶段,如果拦截器决定请求不应该继续,他 可以不调用ActionInvocation实例上的invoke()方法,而是直接返回一个控制字符串。通过这种方式可以停止后续的执行,并且决定哪个 结果被呈现。
3. 做一些后加工。在这个阶段,任何一个返回的拦截器可以修改可以访问的对象的数据作为后加工,但是此时结果已经确定了。
怎么声明拦截器?
下面为Struts 2为我们提供的struts-default.xml文件部分:

- <struts>
...
<interceptors>
<interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>
<interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
<interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>
<interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/>
<interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>
<interceptor name="clearSession" class="org.apache.struts2.interceptor.ClearSessionInterceptor"/>
<interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor"/>
<interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor"/>
<interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/>
<interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>
<interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>
<interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/>
<interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/>
<interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
<interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>
<interceptor name="actionMappingParams" class="org.apache.struts2.interceptor.ActionMappingParametersInteceptor"/>
<interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>
<interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>
<interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>
<interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>
<interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/>
<interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>
<interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
<interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>
<interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>
<interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor"/>
<interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor"/> <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor"/> <interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor"/> <interceptor name="jsonValidation" class="org.apache.struts2.interceptor.validation.JSONValidationInterceptor"/> <interceptor name="annotationWorkflow" class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor"/> <interceptor name="multiselect" class="org.apache.struts2.interceptor.MultiselectInterceptor"/> <!-- Basic stack --> <interceptor-stack name="basicStack"> <interceptor-ref name="exception"/> <interceptor-ref name="servletConfig"/> <interceptor-ref name="prepare"/> <interceptor-ref name="checkbox"/> <interceptor-ref name="multiselect"/> <interceptor-ref name="actionMappingParams"/> <interceptor-ref name="params"> <param name="excludeParams">dojo\..*,^struts\..*</param> </interceptor-ref> <interceptor-ref name="conversionError"/> </interceptor-stack> <!-- Sample validation and workflow stack --> <interceptor-stack name="validationWorkflowStack"> <interceptor-ref name="basicStack"/> <interceptor-ref name="validation"/> <interceptor-ref name="workflow"/> </interceptor-stack> <!-- Sample JSON validation stack --> <interceptor-stack name="jsonValidationWorkflowStack"> <interceptor-ref name="basicStack"/> <interceptor-ref name="validation"> <param name="excludeMethods">input,back,cancel</param> </interceptor-ref> <interceptor-ref name="jsonValidation"/> <interceptor-ref name="workflow"/> </interceptor-stack> <!-- Sample file upload stack --> <interceptor-stack name="fileUploadStack"> <interceptor-ref name="fileUpload"/> <interceptor-ref name="basicStack"/> </interceptor-stack> <!-- Sample model-driven stack --> <interceptor-stack name="modelDrivenStack"> <interceptor-ref name="modelDriven"/> <interceptor-ref name="basicStack"/> </interceptor-stack> <!-- Sample action chaining stack --> <interceptor-stack name="chainStack"> <interceptor-ref name="chain"/> <interceptor-ref name="basicStack"/> </interceptor-stack> <!-- Sample i18n stack --> <interceptor-stack name="i18nStack"> <interceptor-ref name="i18n"/> <interceptor-ref name="basicStack"/> </interceptor-stack> ... </interceptors> <default-interceptor-ref name="defaultStack"/> <default-class-ref class="com.opensymphony.xwork2.ActionSupport"/> </package></struts>

在查看它的关于interceptor部分的dtd文件:

- <!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?, default-class-ref?, global-results?, global-exception-mappings?, action*)>
- ...
- <!ELEMENT interceptors (interceptor|interceptor-stack)+>
- <!ELEMENT interceptor (param*)>
<!ATTLIST interceptor
name CDATA #REQUIRED
class CDATA #REQUIRED
>- <!ELEMENT interceptor-stack (interceptor-ref*)>
<!ATTLIST interceptor-stack
name CDATA #REQUIRED
>- <!ELEMENT interceptor-ref (param*)>
<!ATTLIST interceptor-ref
name CDATA #REQUIRED
>- ...

查看dtd文档可以看到interceptors标签要定义在package标签下,我们对照struts-default.xml可以看到interceptors标签确实定义在package标签下,并且在dtd文档中package元素右边说明中interceptors标签右边带有一个"?"符号,表示该标签要么有且只有1个,要么没有。
再接着查看dtd文档interceptors元素右面有"(interceptor|interceptor-stack)*"的一串字符式子,表示 interceptors标签下可以有0个或多个interceptor标签和interceptor-stack标签,并且不分顺序。此时再对比struts-default.xml文件可以看到interceptors标签下确实有许多interceptor标签和interceptor-stack标签。interceptor标签是用于声明一个独立的拦截器的,而interceptor-stack标签用于组织一系列拦截器的 。
在dtd文档中可以看到interceptor-stack的 name属性为#REQUIRED表示这是必须的属性,你声明一个拦截器栈必须给栈取一个名字。而interceptor标签中有两个属性name和 class它们都是#REQUIRED,所以你想定义一个拦截器就必须指明这两个属性的值,name为拦截器的名字,class为这个拦截器会使用哪一个 类作为它的处理器。还有interceptor- stack标签可以包含许多interceptor-ref标签,这些标签是用于引用你使用interceptor标签声明的拦截器或另外的拦截器栈,它 的name属性的值为interceptor标签声明的拦截器的name值或其他拦截器栈的name值,该属性也是#REQUIRED。可以再次对比 struts-default.xml文档,可以看到这个两个标签的用法与我们的理解完全一致。若还有什么不清楚可以去下载struts的dtd文档那里 有具体的说明。
最后一个package可以定义一组默认拦截器(有且只能有1个,dtd规定) ,例如在struts-default.xml文档中
- <default-interceptor-ref name="defaultStack"/>
定义了默认的拦截器组,这个默认的拦截器组会与这个包内没有显示声明自己的拦截器的所有动作相关联。
现在知道了这些,我们就可以定义拦截器了。
拦截器和拦截器栈的声明:

- <interceptors>
<interceptor name="interceptor1" class="com.test.suxiaolei.intercept.Intercept1"></interceptor>
<interceptor name="interceptor2" class="com.test.suxiaolei.intercept.Intercept2"></interceptor>
<interceptor name="interceptor3" class="com.test.suxiaolei.intercept.Intercept3"></interceptor>- <interceptor-stack name="myStack">
<interceptor-ref name="interceptor1"></interceptor-ref>
<interceptor-ref name="interceptor2"></interceptor-ref>
<interceptor-ref name="interceptor3"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>

最后,一部分拦截器是可以接收参数,若一个拦截器接收参数,那么interceptor-ref元素是向它们传入参数的地方。比如,struts-default.xml文档中的workflow拦截器
- <interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
怎么构建自定义拦截器?
通过实现Interceptor接口
在编写一个拦截器时需要实现com.opensymphony.xwork2.interceptor.Interceptor接口

- public interface Interceptor extends Serializable {
- /**
* Called to let an interceptor clean up any resources it has allocated.
*/
void destroy();- /**
* Called after an interceptor is created, but before any requests are processed using
* {@link #intercept(com.opensymphony.xwork2.ActionInvocation) intercept} , giving
* the Interceptor a chance to initialize any needed resources.
*/
void init();- /**
* Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the
* request by the {@link ActionInvocation} or to short-circuit the processing and just return a String return code.
*
* @param invocation the action invocation
* @return the return code, either returned from {@link ActionInvocation#invoke()}, or from the interceptor itself.
* @throws Exception any system-level error, as defined in {@link com.opensymphony.xwork2.Action#execute()}.
*/
String intercept(ActionInvocation invocation) throws Exception;- }

可以看到,这个简单的接口只定义了3个方法。前两个方法时典型的生命周期方法,让你初始化和清理资源。真正的业务逻辑发生在intercept()方法中。这个方法被ActionInvocation.invoke()方法递归调用。
下面演示一个简单的权限验证的例子:
它的工作原理很简单,当一个请求访问一个安全动作时,我们想检查请求是否是一个通过身份验证的用户发出的。
权限认证拦截器:

- public class AuthenticationInterceptor implements Interceptor
{
private static final long serialVersionUID = -1500368808387165682L;- public void destroy()
{- }
- public void init()
{- }
- public String intercept(ActionInvocation invocation) throws Exception
{
Map<String , Object> session = invocation.getInvocationContext().getSession();- User user = (User) session.get("USER");
- if (user == null)
{
return Action.INPUT;
}
else
{
Action action = (Action) invocation.getAction();
if (action instanceof UserAware)
{
((UserAware) action).setUser(user);
}
}- return invocation.invoke();
}
}

登陆动作组件:

- public class LoginAction extends ActionSupport implements SessionAware
{
private static final long serialVersionUID = 3767975035031881006L;- private String username;
private String password;
private Map<String , Object> session;- public String getUsername()
{
return username;
}- public void setUsername(String username)
{
this.username = username;
}- public String getPassword()
{
return password;
}- public void setPassword(String password)
{
this.password = password;
}- public void setSession(Map<String , Object> session)
{
this.session = session;
}- @Override
public String execute()
{
User user = null;- if (getUsername().equals(getPassword()))
{
user = new User();
user.setUsername(username);
user.setPassword(password);
}- if (user == null)
{
return INPUT;
}
else
{
session.put("USER" , user);
}- return SUCCESS;
}- }

安全动作组件,需要登陆后才可以进入:

- public class TestAction extends ActionSupport implements UserAware
{
private static final long serialVersionUID = 2753590609366162370L;- private User user;
- public User getUser()
{
return user;
}- @Override
public String execute() throws Exception
{
return SUCCESS;
}- public void setUser(User user)
{
this.user = user;
}- }

声明拦截器和为Action配置拦截器:

- <interceptors>
<interceptor name="authentication" class="com.test.suxiaolei.intercept.AuthenticationInterceptor"></interceptor>- <interceptor-stack name="myStack">
<interceptor-ref name="authentication"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>- <action name="login" class="com.test.suxiaolei.action.LoginAction">
<result name="success">/test.jsp</result>
<result name="input">/input.jsp</result>
</action>- <action name="test" class="com.test.suxiaolei.action.TestAction">
<result name="success">/index.jsp</result>
<result name="input">/input.jsp</result>
<interceptor-ref name="myStack"></interceptor-ref>
</action>

登录表单:

- <body>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:textfield name="password" label="password"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form>
</body>

需要登录权限才可以提交的表单:
- <body>
<s:form action="test">
<s:submit value="submit"></s:submit>
</s:form>
</body>
成功结果页面:
- <body>
This is my JSP page. <br>
</body>
测试:
打开服务器tomcat,打开浏览器输入http://localhost:服务器端口号/Web项目名称/test.jsp
点击submit按钮,得到以下结果
由于没有登陆,所以权限不够,不能够提交test.jsp的表单,这里我们设置的拦截器起到了作用,下面我们登录这里账号和密码逻辑很简单,只要一样就好了
输入账号密码之后,我们又回到这个页面了,这次再点击submit按钮
可以看到我们成功进入了TestAction
创建自定义的拦截器还可以扩展com.opensymphony.xwork2.interceptor.AbstractInterceptor类,它 并没有什么高级的地方,它仅仅只是帮我们实现了Interceptor接口,帮我们默认实现了init()和destory()方法:

- public abstract class AbstractInterceptor implements Interceptor {
- /**
* Does nothing
*/
public void init() {
}- /**
* Does nothing
*/
public void destroy() {
}- /**
* Override to handle interception
*/
public abstract String intercept(ActionInvocation invocation) throws Exception;
}

最 后,Struts 2内置了很多的日常Web开发都会用到的拦截器,所以一般不太需要自己开发一个拦截器,内置的拦截器几乎包含了所有日常需要的功能,要想真正运用好 Struts 2必须要了解他们的工作原理,在Struts 2的官方网站上有详细的介绍,可以去哪里找到你需要的东西。
Struts 2知识回顾----拦截器(Intercept)总结的更多相关文章
- [原创]java WEB学习笔记74:Struts2 学习之路--自定义拦截器,struts内建的拦截器
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Struts 2学习笔记——拦截器相关
一.添加国际化支持 默认的struts-deault.xml文件中已经定义了国际化拦截器,内容如下 <!-定义国际化拦截器--> <interceptor name="i1 ...
- Struts学习之自定义拦截器
* 所有的拦截器都需要实现Interceptor接口或者继承Interceptor接口的扩展实现类 * 要重写init().intercept().destroy()方法 * in ...
- Struts框架笔记04_拦截器_标签库
目录 1. Struts2的拦截器 1.1 拦截器概述 1.2 拦截器的实现原理 1.3 Struts的执行流程 1.4 拦截器入门 1.4.1 环境搭建 1.4.2 编写拦截器 1.4.3 配置拦截 ...
- struts文件上传拦截器分析
struts有默认的文件拦截器,一般配置maximumSize就可以了. 知道原理,我们可以写一个类继承它,实现自己的配置上传文件大小的方式. 然后细究页面上传文件的时候,发现了一些问题. act ...
- struts文件上传拦截器maximumSize设置文件大小不起作用
<interceptor-ref name="fileUpload"> <param name="allowedTypes ...
- struts文件上传拦截器中参数的配置(maximumSize,allowedTypes ,allowedExtensions)问题
<interceptor-ref name="fileUpload"> <param name="allowedTypes">image ...
- Spring MVC基础知识整理➣拦截器和自定义注解
概述 Spring MVC中通过注解来对方法或者类进行动态的说明或者标注,类似于配置标识文件的属性信息.当标注的类或者方式被使用时候,通过提取注解信息来达到对类的动态处理.在 MVC中,我们常用的注解 ...
- 2018.12.17 struts.xml 配置自定义拦截器配置
自定义拦截器有三个步骤哦 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PU ...
随机推荐
- floodfill算法解题示例
Flood fill算法是从一个区域中提取若干个连通的点与其他相邻区域区分开(或分别染成不同颜色)的经典算法.因为其思路类似洪水从一个区域扩散到所有能到达的区域而得名.在GNU Go和扫雷中,Floo ...
- Standford CoreNLP
Stanford CoreNLP Stanford CoreNLP提供一组自然语言处理的工具.这些工具可以把原始英语文本作为输入,输出词的基本形式,词的词性标记,判断词是否是公司名.人名等,规格化日期 ...
- UIActionSheet
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIActionSheetDelegate& ...
- Android布局揭秘
前言 今天把对于布局的一些理解写下来,主要内容包括控件的属性的继承关系,控件与容器的属性的关系,以及各种类的属性的使用. 控件的属性种类 通常意义上讲,我们在对一个控件进行属性赋值的时候大体上有种类型 ...
- [大牛翻译系列]Hadoop(22)附录D.2 复制连接框架
附录D.2 复制连接框架 复制连接是map端连接,得名于它的具体实现:连接中最小的数据集将会被复制到所有的map主机节点.复制连接的实现非常直接明了.更具体的内容可以参考Chunk Lam的<H ...
- [译]Redis大冒险
原文:ALCA in Redis-land 一篇对使用Redis在NoSQL的世界中冒险之旅的总结. The legs of our journey 像每次出发一样,先对我们这次的旅程路线做个介绍: ...
- Android设置背景图像重复【整理自网络】
1:在res/drawable文件下新建一个xml文件tool_bar_bg_repeat.xml比如为: <?xml version="1.0" encoding=&quo ...
- SQL中的模糊查询
写个标题先.先来一篇大神的文章:http://www.cnblogs.com/GT_Andy/archive/2009/12/25/1921914.html 练习代码如下: 1.百分号:% 表示任 ...
- C# 实例化接口对象
在head first 设计模式中 用到了很多很多接口对象 首先澄清一个问题,就是接口不仅可以声明对象,而且可以把对象实例化,还可以当做参数被传入. 一.接口回调 这就是继承中的向上转型.父类 FL= ...
- 【转载】Powershell连接世纪互联Office365
$User = "admin@contoso.com" $PWord = ConvertTo-SecureString –String "password" – ...