zoukankan      html  css  js  c++  java
  • MyBatis-Plus 多表联查+分页

    在写东西的过程中,多表联查和分页功能必不可少。当然,crud也很重要

    但是又不想写代码和xml。

    通过苦苦的查找。发现MyBatis-Plus一款国产的框架。优化了许多操作

    本次主要记录一下,多表联查和分页的使用。

    Pom.xml    
        <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.0.7.1</version>
            </dependency>
    //Spring boot方式  
    @EnableTransactionManagement
    @Configuration
    @MapperScan("com.baomidou.cloud.service.*.mapper*")
    public class MybatisPlusConfig {
    
        /**
         * 分页插件
         */
        @Bean
        public PaginationInterceptor paginationInterceptor() {
            return new PaginationInterceptor();
        }
    }

    操作完以上步骤(实体  mapper controller 等已建好)

    @ResponseBody
    @GetMapping("/artList")
       public Map<String,Object>articleList(int page,int limit,Article article){
        Page<Article> pageArt=new Page<Article>(page,limit);
        Page<Article> page1 = articleMapper.findAllAndPage(pageArt); //自定义方法,多表
    //    QueryWrapper<Article> diseaseQueryWrapperw = new QueryWrapper<Article>(article); 
    //    IPage<Article> page1 = articleService.page(pageArt,diseaseQueryWrapperw);  //自带的分页查询。只能单表
    //    List<Article> list = articleService.list();
        int total = (int)page1.getTotal();
        return TableMap.ResultJson(0,total,"ok",page1.getRecords()); //layui table 解析返回格式
    }
    mapper  Xml

    <select id="findAllAndPage" resultType="com.chaoba.shirodemo1.model.Article"> SELECT a.id,a.title,a.uid,a.isDel,a.createTime,a.type,ae.`name` FROM article a JOIN article_enum ae ON a.type=ae.id </select>
    mapper接口
    public interface ArticleMapper extends BaseMapper<Article> {
    Page<Article> findAllAndPage( Page<Article> page);
    }
    
    
    一万年太久,只争朝夕!
  • 相关阅读:
    Django
    MySql、Mongodb和Redis的区别
    数据库读写分离之配置Django实现数据库读写分离
    MySQL数据库优化
    01--web框架本质 wsgiref模块介绍
    CI上传图片 The filetype you are attempting to upload is not allowed.
    微信小程序 swiper和video的autoplay设置冲突问题
    关于手机端页面使用border-radius:50%不能使用div变为圆形问题
    微信小程序支付获取params的时候使用JsApiPay失败
    小程序使用笔记
  • 原文地址:https://www.cnblogs.com/chaoba/p/10434239.html
Copyright © 2011-2022 走看看