2020-09-02

2020-09-02  本文已影响0人  cmeizu
 @Override
    public List<UserDTO> getUserDTO(Integer userId) {
        List<User> users = list(Wrappers.lambdaQuery(User.class)
                .select(User::getId, User::getName, User::getAge, User::getSex)
                .orderByDesc(User::getId)
                .last("limit 3"));
        return users.stream().map(u->{
            UserDTO dto = new UserDTO();
            BeanUtils.copyProperties(u, dto);
            return dto;
        }).collect(Collectors.toList());
    }
==>  Preparing: SELECT id,name,age,sex FROM user ORDER BY id DESC limit 3 
==> Parameters: 
<==    Columns: id, name, age, sex
<==        Row: 10, test1, 10, F
<==        Row: 9, test3, 40, M
<==        Row: 8, test, 18, M
<==      Total: 3

补充上一篇文章列表也是可以的.https://www.jianshu.com/p/4d6e7090fafd

上一篇下一篇

猜你喜欢

热点阅读