Commit 0f395614a6972664435f0fd41ac55afd66797e8c
1 parent
fb7fe564
PSM-5
Showing
2 changed files
with
8 additions
and
39 deletions
src/main/java/com/bsth/controller/BaseController.java
| @@ -3,6 +3,7 @@ package com.bsth.controller; | @@ -3,6 +3,7 @@ package com.bsth.controller; | ||
| 3 | import com.bsth.common.ResponseCode; | 3 | import com.bsth.common.ResponseCode; |
| 4 | import com.bsth.service.BaseService; | 4 | import com.bsth.service.BaseService; |
| 5 | import com.bsth.service.schedule.utils.DataImportExportService; | 5 | import com.bsth.service.schedule.utils.DataImportExportService; |
| 6 | +import com.google.common.base.Splitter; | ||
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.data.domain.Page; | 8 | import org.springframework.data.domain.Page; |
| 8 | import org.springframework.data.domain.PageRequest; | 9 | import org.springframework.data.domain.PageRequest; |
| @@ -17,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile; | @@ -17,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile; | ||
| 17 | import javax.servlet.http.HttpServletResponse; | 18 | import javax.servlet.http.HttpServletResponse; |
| 18 | import java.io.*; | 19 | import java.io.*; |
| 19 | import java.util.HashMap; | 20 | import java.util.HashMap; |
| 21 | +import java.util.List; | ||
| 20 | import java.util.Map; | 22 | import java.util.Map; |
| 21 | 23 | ||
| 22 | /** | 24 | /** |
| @@ -58,8 +60,12 @@ public class BaseController<T, ID extends Serializable> { | @@ -58,8 +60,12 @@ public class BaseController<T, ID extends Serializable> { | ||
| 58 | d = Direction.ASC; | 60 | d = Direction.ASC; |
| 59 | else | 61 | else |
| 60 | d = Direction.DESC; | 62 | d = Direction.DESC; |
| 61 | - | ||
| 62 | - return baseService.list(map, new PageRequest(page, size, new Sort(d, order))); | 63 | + |
| 64 | + // 允许多个字段排序,order可以写单个字段,也可以写多个字段 | ||
| 65 | + // 多个字段格式:{col1},{col2},{col3},....,{coln} | ||
| 66 | + // 每个字段的排序方向都是一致,这个以后再看要不要改 | ||
| 67 | + List<String> list = Splitter.on(",").trimResults().splitToList(order); | ||
| 68 | + return baseService.list(map, new PageRequest(page, size, new Sort(d, list))); | ||
| 63 | } | 69 | } |
| 64 | 70 | ||
| 65 | /** | 71 | /** |
src/main/java/com/bsth/controller/schedule/SchedulePlanInfoController.java
| @@ -2,18 +2,9 @@ package com.bsth.controller.schedule; | @@ -2,18 +2,9 @@ package com.bsth.controller.schedule; | ||
| 2 | 2 | ||
| 3 | import com.bsth.controller.BaseController; | 3 | import com.bsth.controller.BaseController; |
| 4 | import com.bsth.entity.schedule.SchedulePlanInfo; | 4 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 5 | -import com.google.common.base.Splitter; | ||
| 6 | -import org.springframework.data.domain.Page; | ||
| 7 | -import org.springframework.data.domain.PageRequest; | ||
| 8 | -import org.springframework.data.domain.Sort; | ||
| 9 | import org.springframework.web.bind.annotation.RequestMapping; | 5 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
| 11 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 12 | import org.springframework.web.bind.annotation.RestController; | 6 | import org.springframework.web.bind.annotation.RestController; |
| 13 | 7 | ||
| 14 | -import java.util.List; | ||
| 15 | -import java.util.Map; | ||
| 16 | - | ||
| 17 | /** | 8 | /** |
| 18 | * Created by xu on 16/6/16. | 9 | * Created by xu on 16/6/16. |
| 19 | */ | 10 | */ |
| @@ -21,32 +12,4 @@ import java.util.Map; | @@ -21,32 +12,4 @@ import java.util.Map; | ||
| 21 | @RequestMapping("spic") | 12 | @RequestMapping("spic") |
| 22 | public class SchedulePlanInfoController extends BaseController<SchedulePlanInfo, Long> { | 13 | public class SchedulePlanInfoController extends BaseController<SchedulePlanInfo, Long> { |
| 23 | 14 | ||
| 24 | - /** | ||
| 25 | - * | ||
| 26 | - * @Title: list | ||
| 27 | - * @Description: TODO(多条件分页查询) | ||
| 28 | - * @param @param map 查询条件 | ||
| 29 | - * @param @param page 页码 | ||
| 30 | - * @param @param size 每页显示数量 | ||
| 31 | - * @throws | ||
| 32 | - */ | ||
| 33 | - @RequestMapping(method = RequestMethod.GET) | ||
| 34 | - public Page<SchedulePlanInfo> list(@RequestParam Map<String, Object> map, | ||
| 35 | - @RequestParam(defaultValue = "0") int page, | ||
| 36 | - @RequestParam(defaultValue = "10") int size, | ||
| 37 | - @RequestParam(defaultValue = "id") String order, | ||
| 38 | - @RequestParam(defaultValue = "DESC") String direction){ | ||
| 39 | - | ||
| 40 | - Sort.Direction d; | ||
| 41 | - | ||
| 42 | - if(null != direction && direction.equals("ASC")) | ||
| 43 | - d = Sort.Direction.ASC; | ||
| 44 | - else | ||
| 45 | - d = Sort.Direction.DESC; | ||
| 46 | - | ||
| 47 | - // order由 col1,col2,col3 这样传入 | ||
| 48 | - List<String> list = Splitter.on(",").trimResults().splitToList(order); | ||
| 49 | - return baseService.list(map, new PageRequest(page, size, new Sort(d, list))); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | } | 15 | } |