java8 Lambad 표현식 자신의 예

4171 단어
 1  
 2 
 3 service 
 4 
 5 public  E outer(Function function) {
 6 
 7 return dao.outer(function);
 8 }
 9 
10 dao 
11 
12 public  E outer(Function function) {
13 
14 return function.apply(this.sessionFactory.getCurrentSession());
15 }
16 
17 controller 
18 
19 @RequestMapping(value = "/findEntityJson/{pageNum}")
20 public @ResponseBody Object findEntityJson(
21      @PathVariable(value = "pageNum") Integer pageNum){    
22 final int pageSize = 5;    
23 return baseService.outer((session) -> {    
24 JSONObject json = new JSONObject();
25 StringBuffer hql = new StringBuffer();//hql 
26 hql.append("from Entity where 1=1 ");    
27 Query dataQuery = session.createQuery(hql.toString());
28 //  
29 dataQuery.setFirstResult((pageNum - 1) * pageSize).setMaxResults(pageSize);
30 json.put("data", Arrays.stream(dataQuery.list().toArray()).map(Entity.class::cast).collect(Collectors.toList()));
31 //  
32 String hql_1 = "select count(*) " + hql.toString();
33 Query sizeQuery = session.createQuery(hql_1);
34 json.put("size", sizeQuery.uniqueResult());    
35 return json;
36 });
37 }

 
다음으로 전송:https://www.cnblogs.com/bowei/p/8259288.html

좋은 웹페이지 즐겨찾기