com.houkunlin.system.dict.starter.json.DictValidConstraintValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of system-dict-starter Show documentation
Show all versions of system-dict-starter Show documentation
系统数据字典自动翻译成字典文本。可集合系统数据库中存储的用户数据字典,也可使用枚举做系统数据字典,主要用在返回数据给前端时自动把字典值翻译成字典文本信息;
The system data dictionary is automatically translated into dictionary text.
The user data dictionary stored in the system database can be aggregated, and the enumeration can also be used as the system data dictionary.
It is mainly used to automatically translate dictionary values into dictionary text information when returning data to the front end.
The newest version!
package com.houkunlin.system.dict.starter.json;
import com.houkunlin.system.dict.starter.DictUtil;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* 校验字典信息是否在字典列表中。校验字典信息的填写是否符合需求
*
* @author HouKunLin
*/
public class DictValidConstraintValidator implements ConstraintValidator {
private String dictType;
@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
if (dictType == null || value == null) {
return false;
}
return DictUtil.getDictText(dictType, value.toString()) != null;
}
@Override
public void initialize(final DictValid constraintAnnotation) {
this.dictType = constraintAnnotation.value();
}
}