• @validated 验证 List 参数在spring中


     @PostMapping(value = "complete")
        public Vo complete(@Valid @RequestBody @Validated(CompleteTaskRequest.class) ValidList<CompleteTaskRequest> request, BindingResult bindingResult) {
            if (bindingResult.hasErrors()) {
                return super.valid(bindingResult);
            }
        
    }
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public class CompleteTaskRequest extends BaseContext implements Serializable {
    
        @NotBlank(message = "任务id不能为空")
        private String taskId;
    
    
    
    }
    import lombok.Data;
    
    import javax.validation.Valid;
    import java.util.*;
    
    @Data
    public class ValidList<E> implements List<E> {
    
        @Valid
        private List<E> list = new LinkedList<>();
    
        @Override
        public int size() {
            return list.size();
        }
    
        @Override
        public boolean isEmpty() {
            return list.isEmpty();
        }
    
        @Override
        public boolean contains(Object o) {
            return list.contains(o);
        }
    
        @Override
        public Iterator<E> iterator() {
            return list.iterator();
        }
    
        @Override
        public Object[] toArray() {
            return list.toArray();
        }
    
        @Override
        public <T> T[] toArray(T[] a) {
            return list.toArray(a);
        }
    
        @Override
        public boolean add(E e) {
            return list.add(e);
        }
    
        @Override
        public boolean remove(Object o) {
            return list.remove(o);
        }
    
        @Override
        public boolean containsAll(Collection<?> c) {
            return list.containsAll(c);
        }
    
        @Override
        public boolean addAll(Collection<? extends E> c) {
            return list.addAll(c);
        }
    
        @Override
        public boolean addAll(int index, Collection<? extends E> c) {
            return list.addAll(index, c);
        }
    
        @Override
        public boolean removeAll(Collection<?> c) {
            return list.removeAll(c);
        }
    
        @Override
        public boolean retainAll(Collection<?> c) {
            return list.retainAll(c);
        }
    
        @Override
        public void clear() {
            list.clear();
        }
    
        @Override
        public E get(int index) {
            return list.get(index);
        }
    
        @Override
        public E set(int index, E element) {
            return list.set(index, element);
        }
    
        @Override
        public void add(int index, E element) {
            list.add(index, element);
        }
    
        @Override
        public E remove(int index) {
            return list.remove(index);
        }
    
        @Override
        public int indexOf(Object o) {
            return list.indexOf(o);
        }
    
        @Override
        public int lastIndexOf(Object o) {
            return list.lastIndexOf(o);
        }
    
        @Override
        public ListIterator<E> listIterator() {
            return list.listIterator();
        }
    
        @Override
        public ListIterator<E> listIterator(int index) {
            return list.listIterator(index);
        }
    
        @Override
        public List<E> subList(int fromIndex, int toIndex) {
            return list.subList(fromIndex, toIndex);
        }
    }

    @ https://stackoverflow.com/questions/28150405/validation-of-a-list-of-objects-in-spring

  • 相关阅读:
    Web性能压力测试工具之WebBench详解
    Request Header Or Cookie Too Large
    手动删除SVCH0ST.EXE的方法
    微信非80端口网页授权
    微信公众号开发80端口映射解决方案 推荐
    解决微信访问 80 端口的限制问题
    Windows查看所有的端口及端口对应的程序
    Windows环境下,用netstat命令查看某个端口号是否占用
    价值观--我的总结
    价值是事物由人(基于自己的需要和获取的难度而)作出的评价而存在的属性
  • 原文地址:https://www.cnblogs.com/xingzc/p/10025958.html
Copyright © 2020-2023  润新知