The Org.springframework.util.Assert class implements legitimacy detection in Spring, with the following method of Assert:
Assertion Method Description:
1. notnull (Object object)
When Object is not null When an exception is thrown, the Notnull (Object object, String message) method allows you to customize the exception information with a message. The opposite of the Notnull () method assertion rule is isNull (Object object)/isnull (Object object, String message), which requires that the incoming parameter must be null;
2. istrue (Boolean expression)/IsTrue (Boolean expression, String message)
When expression does not throw an exception for true;
3. notempty (Collection Collection)/Notempty (Collection Collection, String message)
throws an exception when the collection contains no elements.
Notempty (map map)/notempty (map map, string message) and Notempty (object[] array, String message)/Notempty (Obje Ct[] Array, String message) to determine the entry of the Map and object[] type respectively;
4. haslength (string text)/Haslength (string text, string message)
Throws an exception when text is null or has a length of 0;
5. HasText (string text)/HasText (string text, string message)
Text cannot be null and must contain at least one character that is not a space, otherwise throws an exception;
6. isinstanceof (class Clazz, Object obj)/isinstanceof (class type, object obj, String message)
If obj cannot be properly styled as clazz the specified class will throw an exception;
7. isassignable (class Supertype, class subtype)/Isassignable (class Supertype, class subtype, String message)
Subtype must be able to match by type to supertype, otherwise an exception will be thrown;
Use the Assert assertion class to simplify code for method-in-parameter detection, such as InputStream getData (String file) after applying the Assert assertion class, its code can be simplified to the following form:
Public InputStream getData (String file) {
Assert.hastext (file, "filename entry is not a valid document address");
① using Spring assertion classes for method-in-parameter detection
...
}
Spring Assert Assertion Tool class