java字段判空方法Assert.hasText详细讲解-示例

时间:2024-10-25 07:44:35

示例 1:基本用法

import org.springframework.util.Assert;

public class CompanyService {

    public void activateCompany(ActivateInfo activateInfo) {
        Assert.hasText(activateInfo.getCompanyName(), "公司名称不能为空!");
        // 其他业务逻辑
    }
}

class ActivateInfo {
    private String companyName;

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }
}