The use of MyBatis paging plug-in Pagehelper

Source: Internet
Author: User
@Configuration public
class Mybatisconfig {
    @Bean public
    pagehelper pagehelper () {
        pagehelper Pagehelper = new Pagehelper ();
        Properties Properties = new properties ();
        Properties.setproperty ("Offsetaspagenum", "true");
        Properties.setproperty ("Rowboundswithcount", "true");
        Properties.setproperty ("reasonable", "true");
        Properties.setproperty ("Supportmethodsarguments", "true");
        Properties.setproperty ("Returnpageinfo", "check");
        Properties.setproperty ("params", "Count=countsql");

        Pagehelper.setproperties (properties);
        Return Pagehelper
    }
}
@Getter
@Setter Public
class Pagingparam implements serializable{

    @Min (value = 1, message = "parameter [Pagenum] Wrong ")
    private int pagenum = 1;

    @Min (value = 1, message = "parameter [pageSize] incorrect")
    private int pageSize =;

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactid>pagehelper </artifactId>
            <version>4.2.1</version>
        </dependency>
   int pagenum = Pagingparam.getpagenum ();
   int pageSize = Pagingparam.getpagesize ();
   Pagehelper.startpage (Pagenum, pageSize);
pageinfo<userdto> PageInfo = new pageinfo<> (list<t> List);  Your data source
  pageinfo.settotal (new pageinfo<> (userinformations). Gettotal ());
  **return new Result (200, "Successful acquisition of all members", Result.constructdata (PageInfo));
 public static <T> map<string, object> constructdata (pageinfo<t> PageInfo)
        {map<string, object> data = new treemap<> ();
        Data.put ("Total", pageinfo.gettotal ());
        Data.put ("Pagenum", Pageinfo.getpagenum ());
        if (pageinfo.getlist () = null | | pageinfo.getlist (). Size () = = 0) {data.put ("list", new arraylist<> ());
        }else {data.put ("list", Pageinfo.getlist ());
    } return data; }
 public result selectallpaging (Pagingparam Pagingparam, httpservletrequest res) {int PA
        Genum = Pagingparam.getpagenum ();

        int pageSize = Pagingparam.getpagesize ();

        String organization = "";
        Pagehelper.startpage (Pagenum, pageSize);
        List<userinformation> userinformations;
        try{userinformations = userinformationmapper.selectbyorganization (organization);
            }catch (Exception e) {e.printstacktrace ();
        Return to new result (400, "unknown error"); } pageinfo<userdto> PageInfo = new Pageinfo<> (Copyfromuserinformationtosuserdto (userinformations, RES)
        );

        Pageinfo.settotal (New pageinfo<> (userinformations). Gettotal ());
    Return to new result (200, "Successful acquisition of all members", Result.constructdata (PageInfo)); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.