controller接参数时dto内部校验逻辑的使用

@ScriptAssert(lang="javascript",script="com.xxx.entity.dto.xxxDTO.check(_this.beginTime,_this.endTime)",groups=CHECK.class,message = "invalid time range")
public class xxxDTO {

   private Long beginTime;

   private Long endTime;
   public interface CHECK {}
   public static boolean check(Long start ,Long end ) {
      if (start >= end) {
            return false;
      }
      else{
         return true;
      }
   }

使用:

@GetMapping()
public void getxxx(@Validated(CHECK.class)  xxxDTO dto) {

  }

猜你喜欢

转载自blog.csdn.net/july_young/article/details/81201912