首页 文章 精选 留言 我的

精选列表

搜索[执行机制],共10017篇文章
优秀的个人博客,低调大师

Laravel实践---middleware生效机制

以前的是5.1版本写的。 现在改成5.6版本。 其中遇到的问题,我会在这个laravel专题中一一指出。 第一个问题是路由时 Route::controller不再支持。 于是,我只好弄成Route:get之类的语法来解决。 第二个问题是中间件如何生效。 写middleware时,不能直接返回view了。。要用response. return response()->view('user'); 然后,将这个中间件,弄进kernel.php里面。 protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'middleware.xxx' => \App\Http\Middleware\XXXMiddleware::class, ]; 最后,不管是在controller的__construct里,还是在routers/web.php里,加入中间件缩写。 Route::get('/xxx','xxxController@getIndex')->middleware('middleware.xxx')->name('user.xxx'); public function __construct(){ $this->middleware('middleware.xxx'); }

优秀的个人博客,低调大师

Android 的消息机制(4)

上面的文章我们演示了如何把一个Message由子线程发送给主线程,但是如何将一个Message从主线程发送给子线程呢?子线程在默认的情况下是没有Looper的,也就没有可能操作子线程的消息队列。我们通过查API文档可以看到: Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until the loop is stopped. Most interaction with a message loop is through the Handler class. 大概意思是,线程在默认情况下是没有Looper的,但是可以通过调用Prepare()方法来运行一个loop,然后使用loop()方法来处理消息直到loop结束。通常的使用方式是: ?[Copy to clipboard] Downloadzuiniuwang.java classLooperThreadextendsThread{ publicHandlermHandler; publicvoidrun(){ Looper.prepare(); mHandler=newHandler(){ publicvoidhandleMessage(Messagemsg){//processincoming //messageshere } }; Looper.loop(); } } 例程如下,基本过程是这样的,启动主线程,然后启动子线程,子线程注册Looper,主线程发送一个Message给子线程,然后子线程的handler处理此消息,再把此消息发送给主线程的消息队列,主线程空间显示此消息~ ?[Copy to clipboard] Downloadzuiniuwang.java /** *MessageExample4.java *com.test.Message * *Function:TODO * *verdateauthor *────────────────────────────────── *2011-3-23Leon * *Copyright(c)2011,TNTAllRightsReserved. */ packagecom.test.Message; importandroid.app.Activity; importandroid.graphics.Color; importandroid.os.Bundle; importandroid.os.Handler; importandroid.os.Looper; importandroid.os.Message; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; importandroid.widget.LinearLayout; importandroid.widget.TextView; /** *ClassName:MessageExample4主线程如何传递消息给子线程Function:TODOADDFUNCTIONReason: *TODOADDREASON * *@authorLeon *@version *@sinceVer1.1 *@Date2011-3-23 */ publicclassMessageExample4extendsActivityimplementsOnClickListener{ privatefinalintWC=LinearLayout.LayoutParams.WRAP_CONTENT; privatefinalintFP=LinearLayout.LayoutParams.FILL_PARENT; publicTextViewtv; privateButtonbtn,btn2; privateHandlerh; publicvoidonCreate(Bundleicicle){ super.onCreate(icicle); LinearLayoutlayout=newLinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); btn=newButton(this); btn.setId(101); btn.setText("testlooper"); btn.setOnClickListener(this); LinearLayout.LayoutParamsparam=newLinearLayout.LayoutParams(100,50); param.topMargin=10; layout.addView(btn,param); btn2=newButton(this); btn2.setId(102); btn2.setText("exit"); btn2.setOnClickListener(this); layout.addView(btn2,param); tv=newTextView(this); tv.setTextColor(Color.WHITE); tv.setText(""); LinearLayout.LayoutParamsparam2=newLinearLayout.LayoutParams(FP,WC); param2.topMargin=10; layout.addView(tv,param2); setContentView(layout); //启动子线程 newmyThread().start(); } publicvoidonClick(Viewv){ switch(v.getId()){ case101: Stringobj="mainThread"; Messagem=h.obtainMessage(1,1,1,obj); h.sendMessage(m); break; case102: finish(); break; } } //------------------------------------------------------ classEHandlerextendsHandler{ publicEHandler(Looperlooper){ super(looper); } @Override publicvoidhandleMessage(Messagemsg){ tv.setText((String)msg.obj); } } //------------------------------------------------------ classmyThreadextendsThread{ privateEHandlermHandler; publicvoidrun(){ Looper.prepare(); h=newHandler(){ publicvoidhandleMessage(Messagemsg){ EHandlerha=newEHandler(Looper.getMainLooper()); Stringobj=(String)msg.obj+",myThread"; Messagem=ha.obtainMessage(1,1,1,obj); ha.sendMessage(m); } }; Looper.loop(); } } } 本文转自 最牛傻蛋 51CTO博客,原文链接:http://blog.51cto.com/zuiniuwang/718336,如需转载请自行联系原作者

优秀的个人博客,低调大师

android 回调机制实例!

详细实现为在类中定义接口。在接口的实现方法中传入參数(也能够不传)。 在调用类中传入新建的接口。并实现未实现的方法。 public class CallBackClass { //传入对应的接口作为參数 public void huidiao(final runDate rundate) { //使用线程取代系统的事件 new Thread() { int i = 0; @Override public void run() { super.run(); while(true) { i++; //传入回调參数 rundate.hui("第" + i + "次回调參数。"); try { sleep(5000); } catch(InterruptedException e) { e.printStackTrace(); } } } }.start(); } //定义接口 public interface runDate { public void hui(String str); } } 在主函数中传入接口參数: public class test { public static void main(String [] args) { CallBackClass callback = new CallBackClass(); callback.huidiao(new CallBackClass.runDate() { @Override public void hui(String str) { System.out.println(str); } }); } } 下一篇自己定义ListView中也会用到接口回调。 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5272689.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册