创建一个Validator

Validator是Cloudopt Next的校验组件,主要用于RESTful注解上,与Intercept使用方法类似。

  1. class TestValidator : Validator {
  2. override fun validate(resource: Resource): Boolean {
  3. return true
  4. }
  5. override fun error(resource: Resource) {
  6. resource.renderText("error")
  7. }
  8. }
  1. public class TestInterceptor implements Interceptor {
  2. @Override
  3. public boolean validate(Resource resource) {
  4. return true;
  5. }
  6. @NotNull
  7. @Override
  8. public void error(Resource resource) {
  9. resource.renderText("error");
  10. }
  11. }

使用Validator

  1. @GET(valid = arrayOf(TestValidator::class))
  1. @GET(value = "/",valid = {TestValidator.class})