断言的使用

字符串判断是否为空

hasText

hasLength

notNull

notEmpty

notNull or notEnoty

字符串判断是否为空

hasText

String a = "";

String b = " ";

String c = null;

String d = "haha";

Assert.hasText(a,"a is null");//a is null

Assert.hasText(b,"b is null");//b is null

Assert.hasText(c,"c is null");//c is null

Assert.hasText(c,"d is null");//true

hasLength

String a = "";

String b = " ";

String c = null;

Assert.hasLength(a,"a is null");//a is null

Assert.hasLength(b,"a is null");//true

Assert.hasLength(c,"a is null");//c is null

notNull

String a = "";

String b = " ";

String c = null;

Assert.notNull(a,"a is null");//true

Assert.notNull(b,"b is null");//true

Assert.notNull(c,"c is null");//c is null

notEmpty

ArrayList<Object> a = new ArrayList<>();

ArrayList<Object> b = new ArrayList<>();

b.add(123);

Assert.notEmpty(a,"a not empty");//a is empty

Assert.notEmpty(b,"b not empty");//true

notNull or notEnoty

@Test

    public void test() {

        String ab[] = new String[]{"a"};

        org.springframework.util.Assert.notEmpty(ab,"ab不能为空");

        String ac[] = new String[]{};

        org.springframework.util.Assert.notEmpty(ac,"ac不能为空");

    }

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容