创建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);
    }

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-10-06
  • 2021-11-27
猜你喜欢
  • 2022-01-01
  • 2021-12-12
  • 2021-09-28
  • 2021-06-01
  • 2022-02-16
  • 2021-08-31
相关资源
相似解决方案