[轉載] Java反射是什么?看這篇絕對會了!

參考鏈接: Java中的util.Arrays與Reflection.Array的示例

作者:火星十一郎 https://www.cnblogs.com/hxsyl?

?

一.概念?

反射就是把Java的各種成分映射成相應的Java類。?

Class類的構造方法是private,由JVM創建。?

?

?反射是java語言的一個特性,它允程序在運行時(注意不是編譯的時候)來進行自我檢查并且對內部的成員進行操作。例如它允許一個java的類獲取他所有的成員變量和方法并且顯示出來。Java 的這一能力在實際應用中也許用得不是很多,但是在其它的程序設計語言中根本就不存在這一特性。例如,Pascal、C 或者 C++ 中就沒有辦法在程序中獲得函數定義相關的信息。(來自Sun)?

?

JavaBean 是 reflection 的實際應用之一,它能讓一些工具可視化的操作軟件組件。這些工具通過 reflection 動態的載入并取得 Java 組件(類) 的屬性。?

反射是從1.2就有的,后面的三大框架都會用到反射機制,涉及到類"Class",無法直接new CLass(),其對象是內存里的一份字節碼.  ?

Class 類的實例表示正在運行的 Java 應用程序中的類和接口。枚舉是一種類,注釋是一種接口。每個數組屬于被映射為 Class 對象的一個類,所有具有相同元素類型和維數的數組都共享該 Class 對象。?

基本的 Java類型(boolean、byte、char、short、int、long、float 和 double)和關鍵字 void 也表示為 Class 對象。Class 沒有公共構造方法。?

Class 對象是在加載類時由 Java 虛擬機以及通過調用類加載器中的 defineClass 方法自動構造的。?

Person p1 = new Person();? ??

//下面的這三種方式都可以得到字節碼? ??

CLass c1 = Date.class();? ??

p1.getClass();? ? ?

//若存在則加載,否則新建,往往使用第三種,類的名字在寫源程序時不需要知道,到運行時再傳遞過來? ??

Class.forName("java.lang.String");? ? ?

Class.forName()字節碼已經加載到java虛擬機中,去得到字節碼;java虛擬機中還沒有生成字節碼 用類加載器進行加載,加載的字節碼緩沖到虛擬機中。 ?

?

?另外,大家可以關注微信公眾號Java技術棧回復:JVM,獲取我整理的系列JVM教程,都是干貨。?

?

考慮下面這個簡單的例子,讓我們看看 reflection 是如何工作的。?

import java.lang.reflect.*;? ? ??

?

public class DumpMethods {? ? ??

? ?public static void main(String args[]) {? ? ??

? ? ? try {? ? ??

? ? ? ? ? ?Class c = Class.forName("java.util.Stack");? ? ??

?

? ? ? ? ? ?Method m[] = c.getDeclaredMethods();? ? ??

?

? ? ? ? ? ?for (int i = 0; i < m.length; i++)? ? ??

? ? ? ? ? ? ? ?System.out.println(m[i].toString());? ? ??

? ? ? }? ? ??

? ? ? catch (Throwable e){? ? ??

? ? ? ? ? ? System.err.println(e);? ? ??

? ? ? }? ? ??

? ?}? ? ??

}? ??

?

public synchronized java.lang.Object java.util.Stack.pop()? ? ?

public java.lang.Object java.util.Stack.push(java.lang.Object)? ? ?

public boolean java.util.Stack.empty()? ? ?

public synchronized java.lang.Object java.util.Stack.peek()? ? ?

public synchronized int java.util.Stack.search(java.lang.Object)? ?

這樣就列出了java.util.Stack 類的各方法名以及它們的限制符和返回類型。這個程序使用 Class.forName 載入指定的類,然后調用 getDeclaredMethods 來獲取這個類中定義了的方法列表。java.lang.reflect.Methods 是用來描述某個類中單個方法的一個類。?

以下示例使用 Class 對象來顯示對象的類名:?

void printClassName(Object obj) {? ??

? ? ? ?System.out.println("The class of " + obj +? ??

? ? ? ? ? ? ? ? ? ? ?" is " + obj.getClass().getName());? ??

}? ? ?

還可以使用一個類字面值(JLS Section 15.8.2)來獲取指定類型(或 void)的 Class 對象。例如:?

System.out.println("The name of class Foo is: "+Foo.class.getName());? ??

在沒有對象實例的時候,主要有兩種辦法。?

//獲得類類型的兩種方式? ? ? ? ? ??

Class cls1 = Role.class;? ? ? ? ? ??

Class cls2 = Class.forName("yui.Role");? ??

注意第二種方式中,forName中的參數一定是完整的類名(包名+類名),并且這個方法需要捕獲異常。現在得到cls1就可以創建一個Role類的實例了,利用Class的newInstance方法相當于調用類的默認的構造器。?

Object o = cls1.newInstance();? ? ?

//創建一個實例? ? ? ? ? ??

//Object o1 = new Role();? ?//與上面的方法等價? ??

二.常用方法  ?

1.isPrimitive(判斷是否是基本類型的字節碼)?

public class TestReflect {? ??

? ? public static void main(String[] args) {? ??

? ? ? ? // TODO Auto-generated method stub? ??

? ? ? ? String str = "abc";? ??

? ? ? ? Class cls1 = str.getClass();? ??

? ? ? ? Class cls2 = String.class;? ??

? ? ? ? Class cls3 = null;//必須要加上null? ??

? ? ? ? try {? ??

? ? ? ? ? ? cls3 = Class.forName("java.lang.String");? ??

? ? ? ? } catch (ClassNotFoundException e) {? ??

? ? ? ? ? ? // TODO Auto-generated catch block? ??

? ? ? ? ? ? e.printStackTrace();? ??

? ? ? ? }? ??

? ? ? ? System.out.println(cls1==cls2);? ??

? ? ? ? System.out.println(cls1==cls3);? ??

?

? ? ? ? System.out.println(cls1.isPrimitive());? ??

? ? ? ? System.out.println(int.class.isPrimitive());//判定指定的 Class 對象是否表示一個基本類型。? ??

? ? ? ? System.out.println(int.class == Integer.class);? ??

? ? ? ? System.out.println(int.class == Integer.TYPE);? ??

? ? ? ? System.out.println(int[].class.isPrimitive());? ??

? ? ? ? System.out.println(int[].class.isArray());? ??

? ? }? ??

}? ??

結果:?

true? ??

true? ??

false? ??

true? ??

false? ??

true? ??

false? ??

true? ??

2.getConstructor和getConstructors()?

java中構造方法沒有先后順序,通過類型和參數個數區分。 ?

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException {? ??

? ? ? ? // TODO Auto-generated method stub? ??

? ? ? ? String str = "abc";? ??

?

? ? ? ? System.out.println(String.class.getConstructor(StringBuffer.class));? ??

? ? }? ??

}? ??

3.Filed類代表某一類中的一個成員變量。?

import java.lang.reflect.Field;? ??

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, Exception {? ??

? ? ? ? ReflectPointer rp1 = new ReflectPointer(3,4);? ??

? ? ? ? Field fieldx = rp1.getClass().getField("x");//必須是x或者y? ??

? ? ? ? System.out.println(fieldx.get(rp1));? ??

?

? ? ? ? /*? ??

? ? ? ? ?* private的成員變量必須使用getDeclaredField,并setAccessible(true),否則看得到拿不到? ??

? ? ? ? ?*/? ??

? ? ? ? Field fieldy = rp1.getClass().getDeclaredField("y");? ??

? ? ? ? fieldy.setAccessible(true);//暴力反射? ??

? ? ? ? System.out.println(fieldy.get(rp1));? ??

?

? ? }? ??

}? ??

?

class ReflectPointer {? ??

?

? ? public int x = 0;? ??

? ? private int y = 0;? ??

?

? ? public ReflectPointer(int x,int y) {//alt + shift +s相當于右鍵source? ??

? ? ? ? super();? ??

? ? ? ? // TODO Auto-generated constructor stub? ??

? ? ? ? this.x = x;? ??

? ? ? ? this.y = y;? ??

? ? }? ??

}? ??

三.典型例題?

1.將所有String類型的成員變量里的b改成a。?

import java.lang.reflect.Field;? ??

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, Exception {? ??

? ? ? ? ReflectPointer rp1 = new ReflectPointer(3,4);? ??

? ? ? ? changeBtoA(rp1);? ??

? ? ? ? System.out.println(rp1);? ??

?

? ? }? ??

?

? ? private static void changeBtoA(Object obj) throws RuntimeException, Exception {? ??

? ? ? ? Field[] fields = obj.getClass().getFields();? ??

?

? ? ? ? for(Field field : fields) {? ??

? ? ? ? ? ? //if(field.getType().equals(String.class))? ??

? ? ? ? ? ? //由于字節碼只有一份,用equals語義不準確? ??

? ? ? ? ? ? if(field.getType()==String.class) {? ??

? ? ? ? ? ? ? ? String oldValue = (String)field.get(obj);? ??

? ? ? ? ? ? ? ? String newValue = oldValue.replace('b', 'a');? ??

? ? ? ? ? ? ? ? field.set(obj,newValue);? ??

? ? ? ? ? ? }? ??

? ? ? ? }? ??

? ? }? ??

}? ??

?

class ReflectPointer {? ??

?

? ? private int x = 0;? ??

? ? public int y = 0;? ??

? ? public String str1 = "ball";? ??

? ? public String str2 = "basketball";? ??

? ? public String str3 = "itcat";? ??

?

? ? public ReflectPointer(int x,int y) {//alt + shift +s相當于右鍵source? ??

? ? ? ? super();? ??

? ? ? ? // TODO Auto-generated constructor stub? ??

? ? ? ? this.x = x;? ??

? ? ? ? this.y = y;? ??

? ? }? ??

?

? ? @Override? ??

? ? public String toString() {? ??

? ? ? ? return "ReflectPointer [str1=" + str1 + ", str2=" + str2 + ", str3="? ??

? ? ? ? ? ? ? ? + str3 + "]";? ??

? ? }? ??

}? ??

2.寫一個程序根據用戶提供的類名,調用該類的里的main方法。?

為什么要用反射的方式呢??

import java.lang.reflect.Field;? ??

import java.lang.reflect.Method;? ??

?

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, Exception {? ??

? ? ? ? String str = args[0];? ??

? ? ? ? /*? ??

? ? ? ? ?* 這樣會數組角標越界,因為壓根沒有這個字符數組? ??

? ? ? ? ?* 需要右鍵在run as-configurations-arguments里輸入b.Inter(完整類名)? ??

? ? ? ? ?*? ? ?

? ? ? ? ?*/? ??

? ? ? ? Method m = Class.forName(str).getMethod("main",String[].class);? ??

? ? ? ? //下面這兩種方式都可以,main方法需要一個參數? ??

?

? ? ? ? m.invoke(null, new Object[]{new String[]{"111","222","333"}});? ??

? ? ? ? m.invoke(null, (Object)new String[]{"111","222","333"});//這個可以說明,數組也是Object? ??

? ? ? ? /*? ??

? ? ? ? ?* m.invoke(null, new String[]{"111","222","333"})? ??

? ? ? ? ?* 上面的不可以,因為java會自動拆包? ??

? ? ? ? ?*/? ??

? ? }? ??

}? ??

?

class Inter {? ??

? ? public static void main(String[] args) {? ??

? ? ? ? for(Object obj : args) {? ??

? ? ? ? ? ? System.out.println(obj);? ??

? ? ? ? }? ??

? ? }? ??

}? ??

3.模擬 **[instanceof**](http://mp.weixin.qq.com/s?__biz=MzI3ODcxMzQzMw==&mid=2247483795&idx=1&sn=20613cdddf5446b0cdcc48ef440ad8c7&chksm=eb5384a5dc240db3a5070cedd0f764ecbe3056b609b6ff11854f2dbd91a017f71c52147c473a&scene=21#wechat_redirect) 操作符?

class S {? ? ??

}? ? ? ?

?

public class IsInstance {? ? ??

? ?public static void main(String args[]) {? ? ??

? ? ? try {? ? ??

? ? ? ? ? ?Class cls = Class.forName("S");? ? ??

? ? ? ? ? ?boolean b1 = cls.isInstance(new Integer(37));? ? ??

? ? ? ? ? ?System.out.println(b1);? ? ??

? ? ? ? ? ?boolean b2 = cls.isInstance(new S());? ? ??

? ? ? ? ? ?System.out.println(b2);? ? ??

? ? ? }? ? ??

? ? ? catch (Throwable e) {? ? ??

? ? ? ? ? ?System.err.println(e);? ? ??

? ? ? }? ? ??

? ?}? ? ??

}? ? ?

在這個例子中創建了一個S 類的 Class 對象,然后檢查一些對象是否是S的實例。Integer(37) 不是,但 new S()是。?

推薦閱讀:instanceof、isInstance、isAssignableFrom?

四.Method類?

代表類(不是對象)中的某一方法。?

import java.lang.reflect.Field;? ??

import java.lang.reflect.Method;? ??

/*? ??

?* 人在黑板上畫圓,涉及三個對象,畫圓需要圓心和半徑,但是是私有的,畫圓的方法? ??

?* 分配給人不合適。? ??

?*? ? ?

?* 司機踩剎車,司機只是給列車發出指令,剎車的動作還需要列車去完成。? ??

?*? ? ?

?* 面試經常考面向對象的設計,比如人關門,人只是去推門。? ??

?*? ? ?

?* 這就是專家模式:誰擁有數據,誰就是專家,方法就分配給誰? ??

?*/? ??

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, Exception {? ??

? ? ? ? String str = "shfsfs";? ??

? ? ? ? //包開頭是com表示是sun內部用的,java打頭的才是用戶的? ??

? ? ? ? Method mtCharAt = String.class.getMethod("charAt", int.class);? ??

? ? ? ? Object ch = mtCharAt.invoke(str,1);//若第一個參數是null,則肯定是靜態方法? ??

? ? ? ? System.out.println(ch);? ??

?

? ? ? ? System.out.println(mtCharAt.invoke(str, new Object[]{2}));//1.4語法? ??

?

? ? }? ??

?

}? ? ?

五.數組的反射?

Array工具類用于完成數組的反射操作。?

同類型同緯度有相同的字節碼。?

int.class和Integer.class不是同一份字節碼,Integer.TYPE,TYPE代表包裝類對應的基本類的字節碼 int.class==Integer.TYPE。?

import java.util.Arrays;? ??

?

/*? ??

?* 從這個例子看出即便字節碼相同但是對象也不一定相同,根本不是一回事? ??

?*? ? ?

?*/? ??

public class TestReflect {? ??

? ? public static void main(String[] args) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, Exception {? ??

? ? ? ? int[] a = new int[3];? ??

? ? ? ? int[] b = new int[]{4,5,5};//直接賦值后不可以指定長度,否則CE? ??

? ? ? ? int[][] c = new int[3][2];? ??

? ? ? ? String[] d = new String[]{"jjj","kkkk"};? ??

? ? ? ? System.out.println(a==b);//false? ??

? ? ? ? System.out.println(a.getClass()==b.getClass());//true? ??

? ? ? ? //System.out.println(a.getClass()==d.getClass());? ? //比較字節碼a和cd也沒法比? ??

? ? ? ? System.out.println(a.getClass());//輸出class [I? ??

? ? ? ? System.out.println(a.getClass().getName());//輸出[I,中括號表示數組,I表示整數? ??

?

? ? ? ? System.out.println(a.getClass().getSuperclass());//輸出class java.lang.Object? ??

? ? ? ? System.out.println(d.getClass().getSuperclass());//輸出class java.lang.Object? ??

?

? ? ? ? //由于父類都是Object,下面都是可以的? ??

? ? ? ? Object obj1 = a;//不可是Object[]? ??

? ? ? ? Object obj2 = b;? ??

? ? ? ? Object[] obj3 = c;//基本類型的一位數組只可以當做Object,非得還可以當做Object[]? ??

? ? ? ? Object obj4 = d;? ??

?

? ? ? ? //注意asList處理int[]和String[]的區別? ??

? ? ? ? System.out.println(Arrays.asList(b));//1.4沒有可變參數,使用的是數組,[[I@1bc4459]? ??

? ? ? ? System.out.println(Arrays.asList(d));//[jjj, kkkk]? ??

?

? ? }? ??

}? ? ?

六.結束語?

以上就是反射機制的簡單的使用,顯然學過spring的朋友一定明白了,為什么可以通過配置文件就可以讓我們獲得指定的方法和變量,在我們創建對象的時候都是通過傳進string實現的,就好像你需要什么,我們去為你生產,還有我們一直在用Object,這就說明java語言的動態特性,依賴性大大的降低了。?

本文版權歸作者火星十一郎所有,歡迎轉載和商用,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利.?

關注公眾號Java技術棧回復"面試"獲取我整理的2020最全面試題及答案。?

推薦去我的博客:?

1.Java JVM、集合、多線程、新特性系列教程?

2.Spring MVC、Spring Boot、Spring Cloud 系列教程?

3.Maven、Git、Eclipse、Intellij IDEA 系列工具教程?

4.Java、后端、架構、阿里巴巴等大廠最新面試題?

覺得不錯,別忘了點贊+轉發哦!?

最后,關注下面的棧長的微信公眾號:Java技術棧,回復:福利,可以免費獲取一份我整理的 2020 最新 Java 面試題,真的非常全(含答案),無任何套路。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540158.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540158.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540158.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[精講-3]Offline Domain Join

從windows 2008 ,windows 7開始起就具備脫機加入域的功能,就是它們在未連接DC的情況下,也可以加入域. 假如環境lab.com ,一臺已加入域的PC (WIN7Client) 和即將加入域的PC(win7-2) 在win7client上run下面這個命令 DC已作了一次預先的動作:創建了computer object 在win7-2上,用本…

[轉載] Java——toArray,集合轉換為數組

參考鏈接&#xff1a; 從ArrayList到Java的Array數組轉換&#xff1a;toArray()方法 package day04; import java.util.ArrayList; import java.util.Collection; /** * 集合轉換為數組 * Collection中定義了兩個方法 * Object[] toArray * <T>Y[] toArray(T[] array) …

c#匿名方法

//以下示例和說明都源于《visual c# 2005 技術內幕》 //匿名函數就是沒有名字的函數&#xff0c;是專用于委托的函數。 using System; using System.Collections.Generic; using System.Text; namespace 匿名方法 { public delegate void DelegateClass(); public dele…

[轉載] JAVA8 創建流的5種方式

參考鏈接&#xff1a; 用Java創建流的10種方法 java8中的流式操作是一個很重要的內容 1、通過 stream 方法把 List 或數組轉換為流&#xff0c;如Arr.stream()&#xff1b; //通過stream方法把List或數組轉換為流 Arrays.asList("a1", "a2", "a3&…

用戶反饋:對 Rafy 開發框架的一些個人建議

對Rafy開發框架的一些個人建議 1、潛在使用群體分析 個人認為使用類似Rafy、AgileEAS.NET、PDF.NET及OpenWorks框架的群體主要為以下幾種&#xff1a; 1.1、小微軟件企業 小微軟件企業&#xff0c;這類軟件公司的開發人員一般在10人以下&#xff0c;多以項目實施為主基本談不上…

[轉載] Java8新特新--Stream語法應用在ArrayList的元素移除和排序

參考鏈接&#xff1a; 如何在Java 8中打印Stream的元素 單元測試&#xff1a; Test public void Test02(){ // 源 ArrayList<Integer> IdsSour new ArrayList<>(); IdsSour.add(5); IdsSour.add(1); IdsSour.add(3); IdsSour.add(2); IdsSour.add(6); IdsSour.a…

搭建iscsi存儲系統

搭建iscsi存儲系統 NAS和SAN服務器概述 NAS網絡附屬存儲&#xff1a; NAS&#xff08;Network Attached Storage)&#xff0c;NAS服務器是連接在網絡上&#xff0c;具備資料存儲功能的服務器&#xff0c;一種與用數據存儲服務器。網絡附屬存儲基于標準網絡協議&#xff08;Tcp/…

[轉載] Java8 Stream流遍歷 如何使用索引

參考鏈接&#xff1a; Java 8中迭代帶有索引的流Stream 1. 問題來源 Java8的Stream流為我們的遍歷集合帶來了方便&#xff0c;基本可以取代for循環了。但是有一些情況需要知道當前遍歷的索引&#xff0c;使用for循環當然可以輕易獲得&#xff0c;但使用stream就很難了。 比如…

Jquery簡單的右側浮動菜單

今天有空稍微看了下Jquery動畫函數animate這個方法&#xff0c;發現可以用這個方法來做下簡單的右側浮動菜單 因為經常做淘寶頁面時候會碰到這樣的效果 以前都是用人家的javascript組件代碼 發現老是用人家也不好&#xff0c;所以今天有空用jqeury中的animate這個方法寫了一個簡…

[轉載] Java8-Stream API 詳解

參考鏈接&#xff1a; 如何在Java 8中從Stream獲取ArrayList 摘要 Stream 作為 Java 8 的一大亮點&#xff0c;它與 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念。它也不同于 StAX 對 XML 解析的 Stream&#xff0c;也不是 Amazon Kinesis 對大數據實時處理…

在Microsoft System Center中利用您的現有投資管理VMware--Veeam MP v6.5

在 Microsoft System Center 中利用您的現有投資管理 VMware VeeamManagement Pack (MP) v6.5 適用于物理、虛擬和備份基礎架構的單一的虛擬管理平臺 前段時間介紹了Veeam Management Pack (MP) v6.0產品&#xff0c;昨天發布了新版本VeeamManagement Pack (MP) v6.5&#xff0…

[轉載] Java關鍵字(Java 8版本)

參考鏈接&#xff1a; 所有Java關鍵字列表 定義 被Java語言賦予了特殊含義&#xff0c;用作專門用途的字符串&#xff08;單詞&#xff09;&#xff0c;這些關鍵字不能用于常量、變量、和任何標識符的名稱。 Java關鍵字(Java 8版本) Java關鍵字(Java 8 以后版本) 注意事…

uiw 1.2.17 發布,基于 React 16 的組件庫

發布&#xff0c; 高品質的UI工具包&#xff0c;React 16的組件庫。 文檔網站&#xff1a;uiw-react.github.io開源倉庫&#xff1a;github.com/uiw-react/u… 更新內容&#xff1a; ? 修復沒有代碼檢測文件匹配*.css。 5712887 ? 添加 .editorconfig 文件. d82dabf ? 給測試…

[轉載] Java中this和super關鍵字分別是什么意思

參考鏈接&#xff1a; Java中的Super關鍵字 this和super關鍵字 this是自身的一個對象&#xff0c;代表對象本身可以理解為指代當前的對象&#xff0c;它可以調用當前對象的屬性、方法和構造方法&#xff0c;一般情況下可以省略&#xff0c;必須使用this的地方是區分出現名字重…

SpringMVC注解HelloWorld

今天整理一下SpringMVC注解 歡迎拍磚 RequestMapping RequestMapping是一個用來處理請求地址映射的注解&#xff0c;可用于類或方法上。用于類上&#xff0c;表示類中的所有響應請求的方法都是以該地址作為父路徑。 RequestMapping注解有六個屬性&#xff0c;下面我們把她分成三…

mysql問答匯集

問:A&#xff0c;B兩臺mysql實現主從復制,A提供寫&#xff0c;B提供讀,那既然B要同步A&#xff0c;當A更新數據的時候&#xff0c;B不也一樣要更新嗎&#xff1f;那B不還是沒有實現負載減輕嗎&#xff1f;還有能通過MYSQL proxy實現3臺mysq均衡l嗎&#xff1f;一臺寫&#xff0…

自制 移動端 純原生 Slider滑動插件

在Google搜關鍵字“slider”或“swiper”能找到一大堆相關插件&#xff0c;自己造輪子是為了能更好的理解其中的原理。 給這個插件取名為“veSlider”是指“very easy slider”非常簡單的一個滑動插件。 這只是個半成品&#xff0c;僅僅實現了手指滑動、自動輪播、跳轉等基本功…

ISA Server 2006 部署步驟

ISA Server 2006 部署步驟 Posted by 尹揆 在這里先把ISA2006的安裝步驟給大家貼出來,后面陸續會有一些配置及日常的應用,希望大家多多指教!呵呵.ISA功能的強大自然不用多說了,一句話只要能想到它就能做到!放入光盤出現在我們面前還是其人性化的界面點默認的下一步吧接受協議序…

ELK 分析 nginx access 日志

注意&#xff1a;修改配置后建議重新創建index 1、nginx 日志文件格式 123log_format elk "$http_clientip | $http_x_forwarded_for | $time_local | $request | $status | $body_bytes_sent | ""$request_body | $content_length | $http_referer | $http_use…

mysql將查詢數據另存

1.查詢mysql的存儲執行目錄&#xff08;secure-file-priv是指定文件夾作為導出文件存放的地方&#xff09;所以需要查詢以下&#xff0c;不然會報1290錯誤 show variables like %secure%;2.查詢并轉存 SELECT * into outfile C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\zo…