码迷,mamicode.com
首页 > 其他好文 > 详细

@Valid解决无法校验List问题

时间:2020-06-13 15:45:42      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:ddd   message   ISE   OLE   dal   void   override   operation   vax   

 

1.新建一个类:ValidList,实现List接口

import javax.validation.Valid;
import java.util.*;
?
public class ValidList<E> implements List<E> {
?
    @Valid
    private List<E> list;
?
    public ValidList() {
        this.list = new ArrayList<>();
    }
?
    public ValidList(List<E> list) {
        this.list = list;
    }
?
    public List<E> getList() {
        return list;
    }
?
    public void setList(List<E> list) {
        this.list = list;
    }
?
    //重写List方法,可省略
    @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.contains(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);
    }
}

 

2.控制器层调用

@PostMapping("l_addBatch")
@ApiOperation("批量添加消息")
public Integer addBatch(@RequestBody @Valid ValidList<MessageAddDTO> messageAddDTOList){
    return sysMessageService.addBatch(messageAddDTOList, getSessionUser().getUserId());
}

 

@Valid解决无法校验List问题

标签:ddd   message   ISE   OLE   dal   void   override   operation   vax   

原文地址:https://www.cnblogs.com/zero666/p/13114754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!