Spring asserts the basic use and method of Assert

foreword

Use the assert keyword to restrict parameter passing (check the validity of method parameters)

use

Assert.notNull(list,"集合不存在");

insert image description here
Format parameters: (assert booleanExpression, assert booleanExpression: messageExpression)
1. When the value of booleanExpression is true, the program continues to execute from the assertion statement;
2. When the value of booleanExpression is false, the program stops executing from the assertion statement and outputs messageException expression the value of the formula;

daily method

  1. Assert.notNull(Object object, “object is required”) - object is not null
  2. Assert.isTrue(Object object, “object must be true”) - object must be true
  3. Assert.notEmpty(Collection collection, “collection must not be empty”) - collection non-empty
  4. Assert.hasLength(String text, “text must be specified”) - character is not null and character length is not 0
  5. Assert.hasText(String text, “text must not be empty”) - text is not null and must contain at least one non-space character
  6. Assert.isInstanceOf(Class clazz, Object obj, “clazz must be of type [clazz]”) - obj must be able to be correctly cast as the class specified by clazz

Guess you like

Origin blog.csdn.net/qq_28545605/article/details/125762389