1. Package page and rows into pageable
pageable pageable = new Pagerequest (page, rows);
2. Create a combined conditional query criteria Object
Specification<fixedarea> spec = new specification<fixedarea> () {
@Override
Public predicate topredicate (root<fixedarea> Root, criteriaquery<?> query, Criteriabuilder CB) {
2.1 Creating a list collection that holds the assembled conditions
arraylist<predicate> predicates = new arraylist<predicate> ();
2.2 Assembling a combination of query conditions
String id = model.getid ();
if (Stringutils.isnotblank (ID)) {
Predicates.add (Cb.equal (Root.get ("id"). As (String.class), id));
}
String company = Model.getcompany ();
if (Stringutils.isnotblank (company)) {
Predicates.add (Cb.like (Root.get ("Company"). As (String.class), "%" +company+ "&");
}
2.3 Creating an predicate array that holds the assembly conditions
predicate[] Predicatearr = new predicate[predicates.size ()];
2.4 Return to assembled conditions
Return Query.where (Predicates.toarray (Predicatearr)). Getrestriction ();
}
};
3. Perform paged queries
page<fixedarea> page = Fixedareaservice.pagequery (spec,pageable);
4. Remove the "many" field in the Fixedarea entity class that will cause no session
String[] excludes = {"Subareas", "Couriers"};
Call the method in Baseaction to convert the results of the query into JSON sent to the foreground
This.write2jsonobject (page, excludes);
-------------------------------------------------------------------------------------------------------------
In Baseaction:
public void Write2jsonobject (page<?> Page, string[] excludes) throws IOException {
Building JSON Object-type data
map<string, object> map = new hashmap<string, object> ();
Map.put ("Total", page.gettotalelements ());
Map.put ("Rows", page.getcontent ());
Jsonconfig: Configuring unwanted properties in JSON data for transformations
Jsonconfig jsonconfig = new Jsonconfig ();
Jsonconfig.setexcludes (excludes);
Convert Map to JSON
String JSON = jsonobject.fromobject (map, Jsonconfig). toString ();
Servletactioncontext.getresponse (). setContentType ("Test/json;charset=utf-8");
Servletactioncontext.getresponse (). Getwriter (). print (JSON);
}
Combined query--Convert Form object to JSON object