先说几个问题:

1、我开始在网上找教程的时候,说是要配置mybaits核心配置。但是我的项目里面根本没有这个配置文件。(我用的是springboot2.0,我是新手,有问题可以提出来)。

2、网上基本都是查询全部数据的,所以sql比较简单。我这个sql也算简单,也就加了一个 where,但就是这么巧出错了。

2-1:这个sql没报错

select a.bid, a.bimgtitle, a.btitle, a.babstract, a.bgood, a.bread, a.bcreatedate, b.cname
        from blog a, categroy b where a.cid = b.cid

2-2:这个sql就报错了。

 select a.bid, a.bimgtitle, a.btitle, a.babstract, a.bgood, a.bread, a.bcreatedate, b.cname
        from blog a, categroy b where a.cid = b.cid;

相信你已经看出出来了,你要查询的结果,最后不可以带  ‘;’。

下面说回正题,配置pagehelper

第一步:pom.xml 依赖

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

第二步:application.yml配置

#pagehelper分页插件
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
    returnPageInfo: check

第三步:service

 这里简单说一下,

比如我这里要查全部的文章。  那么我的sql 就是查询全部的文章就好。

//记住结尾不要加 ; (分号)
select * from blog

在比如,我只查询文章的几个字段,并且有限制,可以这样写sql

 //记住结尾不要加 ; (分号)
 这里的 cid 是分类的id
 select id,title,content, from blog where cid = 'xxxxxxxxxxxxxxxx'

返回的数据 的数据,简单截图一下  json 已经格式化