Java for Web Learning Notes (116): Spring Data (4) Pagination example (top) __java

Source: Internet
Author: User
Example Description

In the example, we'll learn how to page through the user's comments. Join Spring Data Introducing Jar Packs

Join spring data to introduce in POM

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId> spring-data-jpa</artifactid>
    <version>1.11.10.RELEASE</version>
</dependency>
configuration in the root context
@Configuration
@EnableAsync (mode = Advicemode.proxy, Proxytargetclass = false, order = ordered.highest_precedence)
@EnableTransactionManagement (mode = Advicemode.proxy, Proxytargetclass = false, order = Ordered.lowest_precedence )
@EnableJpaRepositories (basepackages = "Cn.wei.flowingflying.customer_support.site.repositories",
                        Entitymanagerfactoryref = "Entitymanagerfactorybean",
                        transactionmanagerref = "Jpatransactionmanager"
)
@EnableScheduling
@ComponentScan (basepackages = "Cn.wei.flowingflying.customer_support.site",
                Excludefilters = @ComponentScan. Filter ({controller.class,controlleradvice.class,endpoint.class})) Public
Class Rootcontextconfiguration implements Asyncconfigurer, schedulingconfigurer{
    ...
}
configuration in the Dispatchservlet context

Simply add @enablespringdatawebsupport, and in the example, we'll use code to customize the setup.

@Configuration @EnableWebMvc @ComponentScan (basepackages = "Cn.wei.flowingflying.customer_support.site", Usedefaultfilters = False, Includefilters = @ComponentScan. Filter (Webcontroller.class)) public class Webse	
    Rvletcontextconfiguration extends webmvcconfigureradapter{private static final Logger log = Logmanager.getlogger ();
    @Inject private ApplicationContext ApplicationContext; ...//"1" sorthandlermethodargumentresolver, the sort parameter in the conversion request//"2" pageablehandlermethodargumentresolver, in the conversion request
       pageable parameter @Override public void Addargumentresolvers (list 

If you have more than one dispatchservlet, and if you need to use paging and sorting, we also make the corresponding settings, the relevant default parameters are different, the code example is as follows:

@Configuration @EnableWebMvc @ComponentScan (basepackages = "Cn.wei.flowingflying.customer_support.site", Usedefaultfilters = False, Includefilters = @ComponentScan. Filter ({restendpoint.class, restendpointadvice. Class})) public class Restservletcontextconfiguration extends webmvcconfigureradapter{private static final Logger Lo
    g = Logmanager.getlogger ();
    @Inject ApplicationContext ApplicationContext;
        ... @Override public void addargumentresolvers (list 

For restful interface paging information in addition to the URL, such as Http://localhost:8080/persons?page=1&size=5&sort, you can also use the HTTP Range headers:range, Content-range, If-range, accept-ranges, and related return code: 206 (Partial Content) 413 (Request Entity Too Large) 416 (requested Range Not satisfiable).


RELATED links: My professional Java for WEB applications related articles

Related Article

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.