Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于wrapper()能否加上以下扩展 #88

Open
gonglb opened this issue Aug 30, 2023 · 0 comments
Open

关于wrapper()能否加上以下扩展 #88

gonglb opened this issue Aug 30, 2023 · 0 comments

Comments

@gonglb
Copy link

gonglb commented Aug 30, 2023

//1、因为大多数情况表模型和业务模型是分开的需要转换,有以下类似的api使用就更方便了
//2、部分业务需要设置空值,但是现在api是不支持设置空值的,需要自己写xml或者全量更新

    /**
       * 设置更新字段为空
       * @param fns
       * @return
     */
    @SafeVarargs
    public final LambdaExampleWrapper<T>  setNull(Fn<T, Object> ... fns) {
        for (Fn<T, Object>  fn : fns) {
            this.example.set(fn.toColumn()+" = NULL ");
        }
        return this;
    }


   public <RE extends Serializable> List<RE> list(Class<RE> returnClass){
        List<T> ts = list();
        List<RE> res = BeanUtil.copys(ts, returnClass);
        if(ts instanceof Page) {
            Page<RE> pageRes = new Page<>();
            pageRes.addAll(res);
            pageRes.setTotal(((Page<T>) ts).getTotal());
            //其他字段按需添加
            return pageRes;
        }
        return res;
    } 

    public <RE extends Serializable> RE one(Class<RE> returnClass){
        T t = one();
        if(t != null) {
            return BeanUtil.copy(t, returnClass);
        }
        return null;
    }

    public <RE extends Serializable> List<RE> top(Integer limit,Class<RE> returnClass){
        List<T> ts = top(limit);
        List<RE> res = BeanUtil.copys(ts, returnClass);
        return res;
    }


    public <RE extends Serializable> RE first(Class<RE> returnClass) {
        T t = first();
        if(t != null) {
            return BeanUtil.copy(t, returnClass);
        }
        return null;
    }
@abel533 abel533 pinned this issue Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant