spring-boot-starter-fluent-validator

springboot start fluent-validator

License

License

Categories

Categories

Spring Boot Container Microservices Ant Build Tools
GroupId

GroupId

com.github.homeant
ArtifactId

ArtifactId

spring-boot-starter-fluent-validator
Last Version

Last Version

1.0.0.M1
Release Date

Release Date

Type

Type

jar
Description

Description

spring-boot-starter-fluent-validator
springboot start fluent-validator
Project URL

Project URL

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

Source Code Management

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

Download spring-boot-starter-fluent-validator

How to add to project

<!-- 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"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-autoconfigure jar
org.springframework.boot : spring-boot-configuration-processor Optional jar
com.baidu.unbiz : fluent-validator-spring jar 1.0.6

provided (3)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar
org.springframework.boot : spring-boot-starter-web jar
org.projectlombok : lombok jar

test (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-aop jar
org.springframework.boot : spring-boot-starter-test jar

Project Modules

There are no modules declared in this project.

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 使用方式统一

Versions

Version
1.0.0.M1