zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }
  • 相关阅读:
    c语言几个字符串处理函数的简单实现
    各种类型排序的实现及比较
    随机洗牌算法Knuth Shuffle和错排公式
    两个栈实现队列
    面试杂题
    面试题——栈的压入、弹出顺序
    Codeforces 455A. Boredom
    PAT A1049. Counting Ones (30)
    Codeforces 895B. XK Segments
    Codeforces 282C. XOR and OR
  • 原文地址:https://www.cnblogs.com/jiefu/p/10049845.html
Copyright © 2011-2022 走看看