MybatisPlus使用介绍

创建UserController测试类

package com.cppdy.controller;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.cppdy.entity.User;
import com.cppdy.mapper.UserMapper;

@RestController
@RequestMapping("user")
public class UserController {
    
    @Autowired
    private UserMapper userMapper;
    
    @RequestMapping("getUserById")
    public Object getUserById(int id) {

        return userMapper.selectById(id);
    }
    
    @RequestMapping("deleteUserById")
    public Object deleteUserById(int id) {

        return userMapper.deleteById(id);
    }
    
    @RequestMapping("getUser")
    public Object getUser() {
        //适配器
        Wrapper<User> wrapper=new EntityWrapper<>();
        wrapper.like("username", "测试");
        //倒序
        wrapper.orderBy("id", false);
        return userMapper.selectList(wrapper);
    }
    
    @RequestMapping("selectPage")
    public Object selectPage(int pageNum,int pageSize) {
        //适配器
        Wrapper<User> wrapper=new EntityWrapper<>();
        
        RowBounds rowBounds=new RowBounds((pageNum-1)*pageSize,pageSize);
        
        return userMapper.selectPage(rowBounds, wrapper);
    }

}

猜你喜欢

转载自www.cnblogs.com/cppdy/p/10049845.html