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