Valiktor是一个类型安全、功能强大且可扩展的流畅DSL,用于验证Kotlin中的对象。
安装Gradle(Groovy):
compile 'org.valiktor:valiktor-core:0.3.1'Gradle(KotlinDSL):
compile("org.valiktor:valiktor-core:0.3.1")Maven:
<dependency> <groupId>org.valiktor</groupId> <artifactId>valiktor-core</artifactId> <version>0.3.1</version></dependency>Forinstallothermodules,see Modules.
开始使用import org.valiktor.validateimport org.valiktor.functions.*data class Employee(val id: Int, val name: String, val email: String) { init { validate(this) { validate(Employee::id).isPositive() validate(Employee::name).isNotBlank().hasSize(min = 1, max = 80) validate(Employee::email).isNotBlank().hasSize(min = 1, max = 50).isEmail() } }}
评论