spring-boot-starter-fluent-validator

springboot start fluent-validator

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы Ant Компиляция и сборка
Группа

Группа

com.github.homeant
Идентификатор

Идентификатор

spring-boot-starter-fluent-validator
Последняя версия

Последняя версия

1.0.0.M1
Дата

Дата

Тип

Тип

jar
Описание

Описание

spring-boot-starter-fluent-validator
springboot start fluent-validator
Ссылка на сайт

Ссылка на сайт

https://github.com/homeant/spring-boot-starter-fluent-validator
Система контроля версий

Система контроля версий

https://github.com/homeant/spring-boot-starter-fluent-validator

Скачать spring-boot-starter-fluent-validator

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.homeant/spring-boot-starter-fluent-validator/ -->
<dependency>
    <groupId>com.github.homeant</groupId>
    <artifactId>spring-boot-starter-fluent-validator</artifactId>
    <version>1.0.0.M1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.homeant/spring-boot-starter-fluent-validator/
implementation 'com.github.homeant:spring-boot-starter-fluent-validator:1.0.0.M1'
// https://jarcasting.com/artifacts/com.github.homeant/spring-boot-starter-fluent-validator/
implementation ("com.github.homeant:spring-boot-starter-fluent-validator:1.0.0.M1")
'com.github.homeant:spring-boot-starter-fluent-validator:jar:1.0.0.M1'
<dependency org="com.github.homeant" name="spring-boot-starter-fluent-validator" rev="1.0.0.M1">
  <artifact name="spring-boot-starter-fluent-validator" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.homeant', module='spring-boot-starter-fluent-validator', version='1.0.0.M1')
)
libraryDependencies += "com.github.homeant" % "spring-boot-starter-fluent-validator" % "1.0.0.M1"
[com.github.homeant/spring-boot-starter-fluent-validator "1.0.0.M1"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-autoconfigure jar
org.springframework.boot : spring-boot-configuration-processor Необязательный jar
com.baidu.unbiz : fluent-validator-spring jar 1.0.6

provided (3)

Идентификатор библиотеки Тип Версия
javax.servlet : javax.servlet-api jar
org.springframework.boot : spring-boot-starter-web jar
org.projectlombok : lombok jar

test (2)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-aop jar
org.springframework.boot : spring-boot-starter-test jar

Модули Проекта

Данный проект не имеет модулей.

fluent-validator

针对hibernate-validator 进行增强,站在巨人的肩膀上,让程序员对数据校验更加得心应手

使用请仔细阅读官方文档:fluent-validator

use

<dependency>
	<groupId>com.github.homeant</groupId>
	<artifactId>spring-boot-starter-fluent-validator</artifactId>
	<version>1.0.0.M1</version>
</dependency>
//此处FluentValid注解
public User install(@FluentValid(UserValidator.class) User user){
	...
}

spring bean

上述** @FluentValid(UserValidator.class) 中的UserValidator.class**交给spring进行管理

Component
pubcli class UserValidator extends Validator{
	
}

config

validator:
  enable: true ## default true

i18n

@Bean
public IMessageService messageService() {
	return new IMessageService() {
		//jdbc or rpc
		@Override
		public List<MessageResource> getAllMessage(Object... args) {
			return null;
		}
	};
}

use of controller

当前版本如果对controller 进行处理需要自己定义**@RestControllerAdvice**,,异常类为com.github.homeant.validator.core.exception.ValidateFailException

@RestControllerAdvice
public class ExceptionHandle {
	@ExceptionHandler(value = ValidateFailException.class)
    public ResponseEntity<Object> Handle(ValidateFailException exception){
		List<Map<String, String>> fields = new ArrayList<>();
		if(null!=exception.getErrors() && exception.getErrors().size()>0) {
			for (int i = 0; i < exception.getErrors().size(); i++) {
				ValidationError r = exception.getErrors().get(i);
				Map<String, String> field = new HashMap<>();
				field.put("field",r.getField());
				field.put("errorMsg",r.getErrorMsg());
				fields.add(field);
			}
		}
		map.put("message",exception.getMessage());
		map.put("state",416);
		map.put("fields", fields);
		return ResponseEntity.status(416).body(map);
    }
}

use of service

在非controller中使用,请自行捕获异常,并处理 develop

版本计划

controller 层校验,将错误信息装载到org.springframework.validation.BindingResult中,和spring validator 使用方式统一

Версии библиотеки

Версия
1.0.0.M1