誰もがインターセプターとセクションの概念に精通していると思います。この記事では、アプリケーション市場でのインターセプターとセクションの使用の一部について説明します。
インターセプターの使用:リクエストが受信されるたびに、このインターセプターの方法が呼び出されます。 PreHandleメソッドがtrueを返す場合、対応するコントローラーが呼び出され続けることを意味します。 falseを返す場合、
パブリッククラスのCheckLoginInterceptor Implements HandlerInterceptor {private logger logger = logger.getLogger(checkloginInterceptor.class); private static string token_valid_msg; static {token_valid_msg = jsonutil.writeobject2json(new amsredultvo(codenum.token_validage); Boolean Prehandle(httpservletrequest request、httpservletresponse応答、オブジェクトハンドラー)例外{//request.getmethod get request is get、postなど。 "*"); //応答タイプResponse.setheader( "Access-control-allow-methods"、 "post、get、options、delete"); //応答ヘッダーセットResponse.setheader( "Access-control-allow-headers"、 "content-type、x-requested-with、x-custom-header"); responstatus frue;ヘッダー文字列username = request.getheader(commonconsts.param_user_name); string usertoken = request.getheader(commonconsts.param_user_token); boolean result = true; strue = request.getRequesturi(); ||。 {Response.setContentType( "text/html; charset = utf-8"); respons.getwriter()。print(token_valid_msg); respons.getWriter()。flush(); respons.getWriter()。 ModelandView ModelandView)スロー例外{} public void aftercompletion(httpservletrequest request、httpservletResponse応答、オブジェクトハンドラー、例外ex)スロー例外{}}セクションの使用:
//悪い割礼通知:ProceedJoinPointタイプのパラメーターを携帯する必要があります//サラウンド通知のプロセス全体は動的プロキシに類似しています:ProceedJoinPointタイプのパラメーターは、ターゲットメソッドを実行するかどうかを決定できます//サラウンド通知に戻り値が必要であり、返品値はターゲットメソッドの返品値です。 @Around( "execution(*com.sowell.controller。*controller。*(..))")public object method(proceedjoinpoint pjd){objectjoinpoint pjd){object result = null; string methodname = pjd.getsignature()。 {logger.info( "要求チャネルが始まる、param {pagenum:" + methodname + "、pagesize:" + args); //前の通知、これの前のコードが結果= pjd.proceed(); recordoprationlog(result、methodname、result); e){e.printstacktrace(); //例外通知logger.error( "around:the method"+methodname+"expection:"+e); //新しいruntimeexception(e);メソッド "+ methodname+"は結果 "+ result); return result;}で終了します;}要約します
上記は、アプリケーション市場のJavaインターセプターとセクションの使用例の詳細な説明の完全な説明です。私はそれが誰にでも役立つことを願っています。興味のある友人は、このサイトの他の関連トピックを引き続き参照できます。欠点がある場合は、それを指摘するためにメッセージを残してください。このサイトへのご支援をありがとうございました!