1.环境初始化
引入依赖
添加插件
在application中配置数据源
添加日志
添加mapper注解,表明mapper接口的位置
2.添加配置类
package top.roud.cms.common;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName: MybatisPlusConfig
* @Description:
* @Author roud
* @Date 2022/6/8
* @Version 1.0
*/
@Configuration
@MapperScan("top.roud.cms.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}
package top.roud.cms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.roud.cms.entity.User;
/**
* @ClassName: UserMapper
* @Description:
* @Author roud
* @Date 2022/6/8
* @Version 1.0
*/
public interface UserMapper extends BaseMapper<User> {
User selectUserByPhonenumberAndPassword(String phonenumber, String password);
User selectUserByPhonenumber(String phonenumber);
}
@Override
public Result findPage(Integer pageNum, Integer pageSize, String search) {
LambdaQueryWrapper<User> wrapper = Wrappers.<User>lambdaQuery();
if(StrUtil.isNotBlank(search)){
wrapper.like(User::getNickname, search);
}
Page<User> userPage = userMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
return Result.success(userPage);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。