All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zys.mybatis.annotation.validate.ExistClass Maven / Gradle / Ivy

There is a newer version: 0.2.7
Show newest version
package com.zys.mybatis.annotation.validate;

import com.zys.mybatis.crud.Query;
import com.zys.mybatis.dao.base.BaseDao;
import com.zys.mybatis.utils.SpringUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author zys
 * @version 1.0
 * @date 2020/12/29 15:58
 */
public class ExistClass implements ConstraintValidator {

    private Exist exist;

    @Override
    public void initialize(Exist exist) {
        this.exist = exist;
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        BaseDao baseDao = exist.classes().equals(BaseDao.class) ? SpringUtil.getPollBean(exist.classes()) : SpringUtil.getBean(exist.classes());
        if (baseDao.count(new Query<>(int.class,exist.tableName(),"count(1)").eq(exist.fieldNames(),value)) > 0) {
            //true 存在通过 false存在不通过
            return exist.flag();
        } else {
            return !exist.flag();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy