商品模块代码提交

This commit is contained in:
Tankaikai
2025-02-20 19:28:16 +08:00
parent 3dd6e2e189
commit 787d67e7b1
14 changed files with 436 additions and 5 deletions

View File

@@ -0,0 +1,36 @@
package com.czg.enums;
/**
* 数据操作枚举
*
* @author tankaikai
* @since 2025-02-20 16:59
*/
public enum CrudEnum {
/**
* 新增
*/
ADD("add"),
/**
* 修改
*/
UPDATE("update"),
/**
* 查询
*/
QUERY("query"),
/**
* 查询
*/
DELETE("delete");
private String value;
CrudEnum(String value) {
this.value = value;
}
public String value() {
return this.value;
}
}

View File

@@ -9,6 +9,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
@@ -30,9 +31,10 @@ public class ValidatorUtil {
/**
* 校验对象
* @param object 待校验对象
* @param groups 待校验的组
* @throws CzgException 校验不通过则报CzgException异常
*
* @param object 待校验对象
* @param groups 待校验的组
* @throws CzgException 校验不通过则报CzgException异常
*/
public static void validateEntity(Object object, Class<?>... groups)
throws CzgException {
@@ -46,4 +48,26 @@ public class ValidatorUtil {
throw new CzgException(constraint.getMessage());
}
}
/**
* 校验对象集合
*
* @param objects 待校验对象集合
* @param groups 待校验的组
* @throws CzgException 校验不通过则报CzgException异常
*/
public static void validateEntityList(List<?> objects, Class<?>... groups)
throws CzgException {
Locale.setDefault(LocaleContextHolder.getLocale());
Validator validator = Validation.byDefaultProvider().configure().messageInterpolator(
new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource())))
.buildValidatorFactory().getValidator();
for (Object object : objects) {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
if (!constraintViolations.isEmpty()) {
ConstraintViolation<Object> constraint = constraintViolations.iterator().next();
throw new CzgException(constraint.getMessage());
}
}
}
}