Java中錯(cuò)誤與異常(Throwable)示例詳解
前言
Throwable 是所有異常和錯(cuò)誤的根類。實(shí)現(xiàn) Throwable 或其子類的對(duì)象才能被 throw 或 catch。
- Error: 表示嚴(yán)重的系統(tǒng)級(jí)問題,通常不應(yīng)該被捕獲或處理,程序通常無法從中恢復(fù)。
- Exception: 表示程序可以處理的問題。分為 運(yùn)行時(shí)異常、 受檢異常 兩類。
- 運(yùn)行時(shí)異常: 不強(qiáng)制要求 try-catch 處理。通常是程序邏輯錯(cuò)誤。
- 受檢異常: 編譯時(shí)必須處理(try-catch 或 throws)。表示外部環(huán)境問題或可恢復(fù)的異常。
java.lang.Throwable :
├── java.lang.Error : 錯(cuò)誤
│ ├── java.lang.VirtualMachineError : JVM 出現(xiàn)嚴(yán)重問題
│ │ ├── java.lang.OutOfMemoryError : 內(nèi)存不足
│ │ ├── java.lang.StackOverflowError : 棧溢出
│ │ ├── java.lang.UnknownError : 未知的虛擬機(jī)錯(cuò)誤
│ │ └── ...
│ ├── java.lang.LinkageError : 類依賴問題
│ │ ├── java.lang.ClassFormatError : 類文件格式錯(cuò)誤
│ │ ├── java.lang.NoClassDefFoundError : 類在編譯時(shí)存在,運(yùn)行時(shí)找不到
│ │ ├── java.lang.UnsupportedClassVersionError : JVM 版本不支持該類版本
│ │ └── ...
│ ├── java.lang.ThreadDeath : 線程被終止(調(diào)用 thread.stop())
│ ├── java.lang.ExceptionInInitializerError : 靜態(tài)初始化出錯(cuò)
│ └── ...
│
└── java.lang.Exception : 異常
├── java.lang.RuntimeException : 運(yùn)行時(shí)異常(非受檢異常)
│ ├── java.lang.ArithmeticException : 算術(shù)異常(除0)
│ ├── java.lang.ArrayStoreException : 數(shù)組存儲(chǔ)類型不匹配
│ ├── java.lang.ClassCastException : 類型轉(zhuǎn)換異常
│ ├── java.lang.IllegalArgumentException : 非法參數(shù)
│ │ ├── java.lang.NumberFormatException : 字符串轉(zhuǎn)數(shù)字失敗
│ │ └── ...
│ ├── java.lang.IndexOutOfBoundsException : 索引越界
│ │ ├── java.lang.ArrayIndexOutOfBoundsException : 數(shù)組索引越界
│ │ └── java.lang.StringIndexOutOfBoundsException : 字符串索引越界(charAt, substring, indexOf, codePointAt)
│ ├── java.lang.NullPointerException : 空指針異常
│ ├── java.lang.SecurityException : 安全限制阻止操作
│ └── ...
│
├── java.io.IOException : I/O異常(受檢異常)
│ ├── java.io.FileNotFoundException : 文件不存在
│ ├── java.io.InterruptedIOException : I/O被中斷
│ └── ...
│
├── java.lang.ClassNotFoundException : 找不到類(受檢異常)
├── java.lang.CloneNotSupportedException : 不允許克隆(受檢異常)
├── java.lang.IllegalAccessException : 訪問權(quán)限不足(受檢異常)
├── java.lang.InstantiationException : 無法實(shí)例化類(受檢異常)
├── java.lang.NoSuchFieldException : 字段不存在(受檢異常)
├── java.lang.NoSuchMethodException : 方法不存在(受檢異常)
├── java.sql.SQLException : 數(shù)據(jù)庫(kù)操作失?。ㄊ軝z異常)
└── 自定義異常(如:MyException)
1. Exception
1.1 自定義異常
可以根據(jù)需要定義自己的異常類,通常繼承 Exception(受檢)或 RuntimeException(非受檢)。
// 自定義受檢異常
public class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
// 自定義運(yùn)行時(shí)異常
public class MyRuntimeException extends RuntimeException {
public MyRuntimeException(String message) {
super(message);
}
}
1.2 RuntimeException
運(yùn)行時(shí)異常。
1.2.1 ArithmeticException 算術(shù)異常
數(shù)學(xué)運(yùn)算中出現(xiàn)異常情況 時(shí)拋出,例如 整數(shù)除以零 或 取模運(yùn)算時(shí)除數(shù)為零。
浮點(diǎn)數(shù)除0不會(huì)拋異常,返回Infinity。
/**
* ArithmeticException: 算術(shù)異常
*/
public static void test_ArithmeticException() {
try {
// 除 0
System.out.println(10/0);
} catch (ArithmeticException e) {
// java.lang.ArithmeticException: / by zero
e.printStackTrace();
}
// 浮點(diǎn)數(shù)除0不會(huì)拋異常?。?!
double result = 10.0 / 0.0;
System.out.println(result); // Infinity
}
1.2.2 ArrayStoreException 數(shù)組存儲(chǔ)類型不匹配
將一個(gè)類型不兼容的對(duì)象插入到數(shù)組中時(shí),在運(yùn)行時(shí)拋出 ArrayStoreException。
/**
* ArrayStoreException: 數(shù)組存儲(chǔ)類型不匹配
*/
public static void test_ArrayStoreException() {
try {
Object[] strings = new String[3];
strings[0] = "hello";
// 嘗試將一個(gè)非 String 類型的元素放入數(shù)組
strings[1] = 123;
} catch (ArrayStoreException e) {
// java.lang.ArrayStoreException: java.lang.Integer
e.printStackTrace();
}
}
1.2.3 ClassCastException 類型轉(zhuǎn)換異常
將一個(gè)對(duì)象轉(zhuǎn)換為它不兼容的類型時(shí),Java 就會(huì)在運(yùn)行時(shí)拋出 ClassCastException。
/**
* ClassCastException: 類型轉(zhuǎn)換異常
*/
public static void test_ClassCastException() {
try {
Object obj = new Integer(10);
// 嘗試向下轉(zhuǎn)型為不兼容的類型
String str = (String) obj;
System.out.println(str);
} catch (ClassCastException e) {
// java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
e.printStackTrace();
}
}
1.2.4 IllegalArgumentException 類型轉(zhuǎn)換異常
在 方法接收到非法或不合適的參數(shù)值 時(shí)拋出,表示傳入的參數(shù)不符合方法的預(yù)期要求。
/**
* IllegalArgumentException: 非法參數(shù)
*/
public static void test_IllegalArgumentException(int i) {
try {
if(i > 5) {
// 手動(dòng)拋出
throw new IllegalArgumentException("傳入?yún)?shù)值不能超過5");
}
} catch (IllegalArgumentException e) {
// java.lang.IllegalArgumentException: 傳入?yún)?shù)值不能超過5
e.printStackTrace();
}
}
1.2.5 NumberFormatException 字符串轉(zhuǎn)數(shù)字失敗
將字符串轉(zhuǎn)換為數(shù)值類型(如 int、double 等)失敗時(shí)拋出。
/**
* NumberFormatException: 字符串轉(zhuǎn)數(shù)字失敗
*/
public static void test_NumberFormatException() {
try {
String str = "123abc";
Integer.parseInt(str);
} catch (NumberFormatException e) {
// java.lang.NumberFormatException: For input string: "123abc"
e.printStackTrace();
}
}
1.2.6 ArrayIndexOutOfBoundsException 數(shù)組越界異常
訪問數(shù)組元素時(shí)使用了非法索引(負(fù)數(shù)或大于等于數(shù)組長(zhǎng)度的值) 時(shí)拋出。
/**
* ArrayIndexOutOfBoundsException: 數(shù)組越界異常
*/
public static void test_ArrayIndexOutOfBoundsException() {
try {
Integer[] integers = new Integer[5];
integers[5] = 0;
} catch (ArrayIndexOutOfBoundsException e) {
// java.lang.ArrayIndexOutOfBoundsException: 5
e.printStackTrace();
}
}
1.2.7 StringIndexOutOfBoundsException 字符串越界異常
訪問字符串中字符時(shí)使用了非法索引(負(fù)數(shù)或大于等于字符串長(zhǎng)度) 時(shí)拋出。
/**
* StringIndexOutOfBoundsException: 字符串越界異常
*/
public static void test_StringIndexOutOfBoundsException() {
try {
String s = "12345";
s.charAt(5);
} catch (StringIndexOutOfBoundsException e) {
// java.lang.StringIndexOutOfBoundsException: String index out of range: 5
e.printStackTrace();
}
}
1.2.8 NullPointerException 空指針異常
嘗試在 一個(gè)為 null 的對(duì)象引用上調(diào)用方法或訪問屬性 時(shí),就會(huì)拋出 NullPointerException。
/**
* NullPointerException: 空指針異常
*/
public static void test_NullPointerException() {
try {
String s = null;
s.length();
} catch (NullPointerException e) {
// java.lang.NullPointerException
e.printStackTrace();
}
}
1.2.9 SecurityException 安全限制阻止操作
程序試圖執(zhí)行某些受安全管理器限制的操作時(shí)拋出。
/**
* SecurityException: 安全限制阻止操作
*/
public static void test_SecurityException() {
// 設(shè)置一個(gè)安全管理器
System.setSecurityManager(new SecurityManager());
try {
String property = System.getProperty("user.name");
System.out.println(property);
} catch (SecurityException e) {
// java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.name" "read")
e.printStackTrace();
}
}
1.3 IOException
在進(jìn)行文件讀寫、網(wǎng)絡(luò)通信、流操作等 I/O 操作時(shí)拋出。
1.3.1 FileNotFoundException(受檢異常)
試圖打開一個(gè)不存在的文件 或 路徑無效 時(shí)拋出的異常。
- FileNotFoundException:
- InterruptedIOException: I/O 操作被中斷(線程被中斷)時(shí)拋出。
/**
* IOException: IO異常(受檢異常)
*/
public static void test_IOException() {
// 設(shè)置一個(gè)安全管理器
try {
FileReader fileReader = new FileReader("file.txt");
int read = fileReader.read();
while(read != -1) {
System.out.println((char)read);
read = fileReader.read();
}
fileReader.close();
} catch (IOException e) {
// FileNotFoundException 文件不存在異常
// java.io.FileNotFoundException: file.txt (系統(tǒng)找不到指定的文件。)
e.printStackTrace();
}
}
1.3.2 InterruptedIOException
I/O 操作被中斷(線程被中斷)時(shí)拋出。
/**
* InterruptedIOException: I/O 操作中斷
*/
public static void test_InterruptedIOException() {
Thread ioThread = new Thread(() -> {
try (InputStream is = new PipedInputStream()) {
System.out.println("開始讀取...");
is.read(); // 阻塞等待輸入
} catch (InterruptedIOException e) {
System.out.println("I/O 操作被中斷: " + e.getMessage());
} catch (IOException e) {
// java.io.IOException: Pipe not connected
e.printStackTrace();
}
});
ioThread.start();
// 中斷線程
ioThread.interrupt();
}
1.4 反射相關(guān)異常
1.4.1 ClassNotFoundException 找不到類(受檢異常)
該異常通常在 使用類名字符串動(dòng)態(tài)加載類(如通過 Class.forName())時(shí)拋出。
/**
* ClassNotFoundException: 找不到類
*/
public static void test_ClassNotFoundException() {
try {
// 嘗試加載一個(gè)不存在的類
Class<?> clazz = Class.forName("com.example.NonExistentClass");
} catch (ClassNotFoundException e) {
// java.lang.ClassNotFoundException: com.example.NonExistentClass
e.printStackTrace();
}
}
1.4.2 IllegalAccessException 訪問權(quán)限不足(受檢異常)
在運(yùn)行時(shí)通過反射機(jī)制嘗試訪問類、方法、字段等成員時(shí),如果該成員的訪問權(quán)限不足(例如是 private),并且沒有通過 setAccessible(true) 顯式開啟訪問權(quán)限,就會(huì)拋出該異常。
/**
* IllegalAccessException : 訪問權(quán)限不足
*/
public static void test_IllegalAccessException() {
class Person {
private String name = "Alice";
}
try {
Person person = new Person();
Field field = person.getClass().getDeclaredField("name");
// 嘗試獲取私有字段的值,但未設(shè)置可訪問
System.out.println(field.get(person)); // 拋出 IllegalAccessException
} catch (NoSuchFieldException | IllegalAccessException e) {
// java.lang.IllegalAccessException: Class com.lkm.test.Test_Throwable can not access a member of class com.lkm.test.Test_Throwable$1Person with modifiers "private"
e.printStackTrace();
}
}
1.4.3 InstantiationException 無法實(shí)例化類(受檢異常)
通常在使用 反射機(jī)制 創(chuàng)建類的實(shí)例時(shí)拋出,尤其是在調(diào)用 Class.newInstance() 或 Constructor.newInstance() 時(shí),如果目標(biāo)類無法被實(shí)例化,就會(huì)拋出這個(gè)異常。
- 類是抽象類(abstract):抽象類不能直接實(shí)例化
- 類是接口(interface):接口也不能直接實(shí)例化
- 沒有無參構(gòu)造函數(shù):如果類沒有默認(rèn)構(gòu)造函數(shù)(0個(gè)參數(shù)),而你使用 Class.newInstance()
- 構(gòu)造函數(shù)拋出異常:構(gòu)造函數(shù)執(zhí)行過程中拋出了異常,也會(huì)導(dǎo)致此異常
1.4.4 NoSuchFieldException 字段不存在(受檢異常)
通常在使用 反射(Reflection) 機(jī)制訪問類的字段(成員變量)時(shí)拋出,表示你嘗試訪問的字段在目標(biāo)類中 不存在。
/**
* NoSuchFieldException : 字段不存在
*/
public static void test_NoSuchFieldException() {
class Person {
private String name;
public int age;
}
try {
Class<?> clazz = Person.class;
Field field = clazz.getField("gender"); // 嘗試訪問不存在的 public 字段
} catch (NoSuchFieldException e) {
// java.lang.NoSuchFieldException: gender
e.printStackTrace();
}
}
1.4.5 NoSuchMethodException 方法不存在(受檢異常)
通常在使用 反射(Reflection) 機(jī)制訪問類的方法時(shí)拋出,表示你嘗試調(diào)用的方法在目標(biāo)類中 不存在,或者參數(shù)類型不匹配。
/**
* NoSuchMethodException : 方法不存在
*/
public static void test_NoSuchMethodException() {
class Person {
public void sayHello() {
System.out.println("Hello");
}
}
try {
Class<?> clazz = Person.class;
Method method = clazz.getMethod("sayGoodbye"); // 方法不存在
} catch (NoSuchMethodException e) {
// java.lang.NoSuchMethodException: com.lkm.test.Test_Throwable$1Person.sayGoodbye()
e.printStackTrace();
}
}
1.5 CloneNotSupportedException 不允許克?。ㄊ軝z異常)
該異常通常在調(diào)用 Object.clone() 方法時(shí),如果對(duì)象的類 沒有實(shí)現(xiàn) Cloneable 接口,就會(huì)拋出。
// class Person implements Cloneable
// 沒有實(shí)現(xiàn) Cloneable 是不允許調(diào)用 clone 進(jìn)行克隆的
static class Person {
String name;
public Person(String name) {
this.name = name;
}
@Override
public Person clone() throws CloneNotSupportedException {
return (Person) super.clone();
}
}
/**
* CloneNotSupportedException : 不允許克隆
*/
public static void test_CloneNotSupportedException() {
Person p1 = new Person("Alice");
try {
Person p2 = (Person) p1.clone();
} catch (CloneNotSupportedException e) {
// java.lang.CloneNotSupportedException: com.lkm.test.Test_Throwable$Person
e.printStackTrace();
}
}
1.6 SQLException 數(shù)據(jù)庫(kù)操作失敗(受檢異常)
用于處理 數(shù)據(jù)庫(kù)訪問錯(cuò)誤 的一個(gè) 受檢異常(Checked Exception),它通常在使用 JDBC(Java Database Connectivity)與數(shù)據(jù)庫(kù)交互時(shí)拋出。當(dāng)執(zhí)行 SQL 語(yǔ)句、連接數(shù)據(jù)庫(kù)、處理結(jié)果集等操作失敗時(shí),JDBC 驅(qū)動(dòng)會(huì)拋出 SQLException。
- 數(shù)據(jù)庫(kù)連接失?。哄e(cuò)誤的 URL、用戶名、密碼
- SQL 語(yǔ)法錯(cuò)誤:SQL 語(yǔ)句拼寫錯(cuò)誤、表名不存在
- 數(shù)據(jù)庫(kù)服務(wù)未啟動(dòng):數(shù)據(jù)庫(kù)服務(wù)器宕機(jī)或無法訪問
- 權(quán)限不足:當(dāng)前用戶沒有執(zhí)行該操作的權(quán)限
- 網(wǎng)絡(luò)問題:數(shù)據(jù)庫(kù)服務(wù)器無法連接(超時(shí))
- 數(shù)據(jù)類型不匹配:插入或查詢時(shí)類型不匹配
- 主鍵沖突:插入重復(fù)主鍵
- 空指針訪問:使用已關(guān)閉的 Connection、Statement、ResultSet
/**
* SQLException : 數(shù)據(jù)庫(kù)操作失敗
*/
public static void test_SQLException() {
String url = "jdbc:mysql://localhost:3306/nonexistentdb"; // 錯(cuò)誤的數(shù)據(jù)庫(kù)名
String user = "root";
String password = "wrongpassword"; // 錯(cuò)誤密碼
try {
Connection conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
System.out.println("SQLException: " + e.getMessage()); // SQLException: No suitable driver found for jdbc:mysql://localhost:3306/nonexistentdb
System.out.println("SQLState: " + e.getSQLState()); // SQLState: 08001
System.out.println("Error Code: " + e.getErrorCode()); // Error Code: 0
// java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/nonexistentdb
e.printStackTrace();
}
}
2. Error
2.1 VirtualMachineError
JVM 出現(xiàn)嚴(yán)重問題。
2.1.1 OutOfMemoryError 內(nèi)存不足
表示 Java 虛擬機(jī)(JVM)在運(yùn)行過程中無法分配對(duì)象,因?yàn)閮?nèi)存不足,并且垃圾收集器已經(jīng)嘗試回收內(nèi)存但仍然沒有足夠的空間。
// 內(nèi)存泄漏
// 最后報(bào)錯(cuò) Caused by: java.lang.OutOfMemoryError: Java heap space
public static void test_OutOfMemoryError() {
List<byte[]> list = new ArrayList<>();
while (true) {
list.add(new byte[1024 * 1024]); // 每次分配1MB
}
}
2.1.2 StackOverflowError 棧溢出
通常發(fā)生在程序遞歸調(diào)用過深或調(diào)用棧溢出的情況下,也就是說,程序調(diào)用了太多方法而沒有返回,導(dǎo)致 JVM 的調(diào)用??臻g不足。
// 最后報(bào)錯(cuò) Caused by: java.lang.StackOverflowError
public static void test_StackOverflowError() {
System.out.println("Recursion");
test_StackOverflowError(); // 無限遞歸
}
2.1.3 UnknownError
未知的虛擬機(jī)錯(cuò)誤。
- JVM 內(nèi)部錯(cuò)誤:JVM 在運(yùn)行過程中遇到不可恢復(fù)的內(nèi)部錯(cuò)誤。
- 本地方法調(diào)用失?。和ㄟ^ JNI(Java Native Interface)調(diào)用的本地代碼(如 C/C++)出現(xiàn)了嚴(yán)重錯(cuò)誤。
- 資源耗盡但未歸類為 OutOfMemoryError:某些資源(如文件句柄、線程、內(nèi)存映射等)耗盡,但 JVM 沒有為該錯(cuò)誤定義特定的 Error 類型。
- JVM bug:在極少數(shù)情況下,可能是 JVM 本身的 bug 導(dǎo)致拋出該錯(cuò)誤。
2.2 LinkageError
類依賴問題。
2.2.1 ClassFormatError 類文件格式錯(cuò)誤
表示 JVM 試圖讀取一個(gè) .class 文件,但該文件的格式不符合 Java 類文件的規(guī)范。這通常發(fā)生在類文件損壞、被非法修改,或者是由不兼容的編譯器生成的情況下。
// 最后報(bào)錯(cuò) java.lang.ClassNotFoundException: InvalidClass
public static void test_ClassFormatError() {
try {
// 嘗試加載一個(gè)非法格式的類文件
ClassLoader.getSystemClassLoader().loadClass("InvalidClass");
} catch (Throwable t) {
t.printStackTrace();
}
}
2.2.2 NoClassDefFoundError 類在編譯時(shí)存在,運(yùn)行時(shí)找不到
表示 JVM 在編譯時(shí)能找到某個(gè)類,但在運(yùn)行時(shí)找不到該類的定義。這通常是由類路徑(classpath)配置錯(cuò)誤、依賴缺失或類加載失敗引起的。
2.2.3 UnsupportedClassVersionError JVM 版本不支持該類版本
表示 JVM 試圖加載一個(gè)類文件,但該類文件是由更高版本的 Java 編譯器編譯的,當(dāng)前 JVM 無法識(shí)別或支持該類文件的版本。
類文件由高版本 JDK 編譯,但運(yùn)行在低版本 JVM 上
例如:使用 JDK 17 編譯 .class 文件,但在 JRE 8 上運(yùn)行。
JVM 版本與類文件版本不兼容
每個(gè) Java 版本都有一個(gè)對(duì)應(yīng)的類文件主版本號(hào)(major version),JVM 只能加載它支持的類文件版本。
2.3 ThreadDeath 線程被終止
表示一個(gè)線程被強(qiáng)制終止(通過調(diào)用 Thread.stop() 方法)。這個(gè)類的設(shè)計(jì)目的是為了在 Thread.stop() 被調(diào)用時(shí)拋出一個(gè)特殊的 Error,以表明線程是被外部強(qiáng)制終止的,而不是正常退出。
在 Java 的早期版本中,Thread.stop() 方法曾被用來立即終止一個(gè)線程的執(zhí)行。為了表示線程不是正常退出,JVM 會(huì)拋出一個(gè) ThreadDeath 異常(它是 Error 的子類),并允許線程通過 try-catch 捕獲它。
現(xiàn)在已經(jīng)不推薦使用 Thread.stop() 了,因此了解一下即可。
// 最后拋出 ThreadDeath,打印了 Caught ThreadDeath, doing cleanup...
public static void test_ThreadDeath() {
Thread t = new Thread(() -> {
try {
while (true) {
System.out.println("Thread is running...");
Thread.sleep(1000);
}
} catch (ThreadDeath td) {
System.out.println("Caught ThreadDeath, doing cleanup...");
// 做一些清理工作
throw td; // 重新拋出以確保線程真正終止
} catch (InterruptedException e) {
e.printStackTrace();
}
});
t.start();
try {
Thread.sleep(3000); // 主線程等待3秒
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Stopping thread...");
t.stop(); // 強(qiáng)制終止線程,拋出 ThreadDeath
}
2.4 ExceptionInInitializerError 靜態(tài)初始化出錯(cuò)
表示在類初始化過程中發(fā)生了異常。這個(gè)錯(cuò)誤通常發(fā)生在類的靜態(tài)初始化塊(static initializer block)或靜態(tài)變量初始化時(shí)拋出了異常。
static {
if (true) {
throw new RuntimeException("Static initializer failed!");
}
}
// Exception in thread "main" java.lang.ExceptionInInitializerError
// Caused by: java.lang.RuntimeException: Static initializer failed!
public static void test_ExceptionInInitializerError() {
System.out.println("This will not be printed.");
}
總結(jié)
到此這篇關(guān)于Java中錯(cuò)誤與異常(Throwable)的文章就介紹到這了,更多相關(guān)Java錯(cuò)誤與異常Throwable內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
新手初學(xué)Java對(duì)象內(nèi)存構(gòu)成
這篇文章主要介紹了深入理解JVM之Java對(duì)象的創(chuàng)建、內(nèi)存布局、訪問定位,結(jié)合實(shí)例形式詳細(xì)分析了Java對(duì)象的創(chuàng)建、內(nèi)存布局、訪問定位相關(guān)概念、原理、操作技巧與注意事項(xiàng),需要的朋友可以參考下2021-07-07
SpringMVC自定義攔截器實(shí)現(xiàn)過程詳解
這篇文章主要介紹了SpringMVC自定義攔截器實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
Mybatis之collection標(biāo)簽中javaType和ofType屬性的區(qū)別說明
這篇文章主要介紹了Mybatis之collection標(biāo)簽中javaType和ofType屬性的區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
Spring?Boot父子工程POM依賴關(guān)系舉例詳解
這篇文章主要介紹了Spring?Boot父子工程POM依賴關(guān)系的相關(guān)資料,Spring Boot父子工程通過Maven繼承機(jī)制實(shí)現(xiàn)統(tǒng)一版本、依賴和插件管理,模塊化開發(fā)與代碼復(fù)用,提升項(xiàng)目可維護(hù)性與效率,需要的朋友可以參考下2025-08-08
java鏈表應(yīng)用--基于鏈表實(shí)現(xiàn)隊(duì)列詳解(尾指針操作)
這篇文章主要介紹了java鏈表應(yīng)用--基于鏈表實(shí)現(xiàn)隊(duì)列,結(jié)合實(shí)例形式分析了java基于鏈表實(shí)現(xiàn)隊(duì)列尾指針相關(guān)操作使用技巧,需要的朋友可以參考下2020-03-03
Java將集合List轉(zhuǎn)換成String字符串(或String轉(zhuǎn)換成List)詳解
今天在寫項(xiàng)目的時(shí)候遇到一個(gè)問題,就是要把得到的一個(gè)集合轉(zhuǎn)換成字符串,下面這篇文章主要給大家介紹了關(guān)于Java將集合List轉(zhuǎn)換成String字符串(或String轉(zhuǎn)換成List)的相關(guān)資料,需要的朋友可以參考下2023-06-06
java多線程實(shí)現(xiàn)同步鎖賣票實(shí)戰(zhàn)項(xiàng)目
本文主要介紹了java多線程實(shí)現(xiàn)同步鎖賣票實(shí)戰(zhàn)項(xiàng)目,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01

