MybatisPlus使用介绍
Posted cppdy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); } }
以上是关于MybatisPlus使用介绍的主要内容,如果未能解决你的问题,请参考以下文章