展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

Mybatis plus入门(十一):序列化

目录

  • 使用BaseMapper接口中的selectPage方法,传入参数Page和Wrappers

代码案例

  • 使用BaseMapper接口中的selectPage方法,传入参数Page和Wrappers
    @RequestMapping("/test2")
    @ResponseBody
    public String test2(){
        // 分页查询
        Page<User> page = new Page<>(1, 5);
        // 升序排序
        page.addOrder(OrderItem.asc("age"));
        // age为20,根据name模糊查询
        Page<User> userIPage = mapper.selectPage(page, Wrappers.<User>lambdaQuery().eq(User::getAge, 20).like(User::getName, "Jack"));
        String json = JSON.toJSONString(page);
        System.out.println(json);
        Page<User> page1 = JSON.parseObject(json, new TypeReference<Page<User>>() {});
        List<User> records1 = page1.getRecords();
        records1.forEach(System.out::println);
        return "success";
    }

# 控制台
SELECT id, name, age, email FROM user WHERE (age = ? AND name LIKE ?) ORDER BY age ASC LIMIT ?

{
    "current": 1,
    "hitCount": false,
    "optimizeCountSql": true,
    "orders": [
        {
            "asc": true,
            "column": "age"
        }
    ],
    "pages": 3,
    "records": [
        {
            "age": 20,
            "email": "test2@baomidou.com",
            "id": 2,
            "name": "Jack"
        },
        {
            "age": 20,
            "email": "test2@baomidou.com",
            "id": 3,
            "name": "Jack"
        },
        {
            "age": 20,
            "email": "test2@baomidou.com",
            "id": 4,
            "name": "Jack"
        },
        {
            "age": 20,
            "email": "test2@baomidou.com",
            "id": 5,
            "name": "Jack"
        },
        {
            "age": 20,
            "email": "test2@baomidou.com",
            "id": 6,
            "name": "Jack"
        }
    ],
    "searchCount": true,
    "size": 5,
    "total": 13
}

User(id=2, name=Jack, age=20, email=test2@baomidou.com)
User(id=3, name=Jack, age=20, email=test2@baomidou.com)
User(id=4, name=Jack, age=20, email=test2@baomidou.com)
User(id=5, name=Jack, age=20, email=test2@baomidou.com)
User(id=6, name=Jack, age=20, email=test2@baomidou.com)
posted @ 2022-04-28 15:19  DogLeftover  阅读(263)  评论(0编辑  收藏  举报