HbaseQueryController.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.winhc.phoenix.example.controller;
  2. import com.winhc.phoenix.example.service.HbaseQueryService;
  3. import com.winhc.phoenix.example.vo.ResponseVo;
  4. import io.swagger.annotations.Api;
  5. import io.swagger.annotations.ApiOperation;
  6. import lombok.AllArgsConstructor;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.web.bind.annotation.*;
  9. import java.util.List;
  10. /**
  11. * @Author: XuJiakai
  12. * @Date: 2020/9/1 17:44
  13. * @Description:
  14. */
  15. @Slf4j
  16. @AllArgsConstructor
  17. @RestController
  18. @Api(tags = "hbase查询", value = "hbase")
  19. @RequestMapping("hbase")
  20. public class HbaseQueryController {
  21. private HbaseQueryService hbaseQueryService;
  22. @ApiOperation(value = "scan前辍匹配,默认返回前100条数据")
  23. @GetMapping("scan/{tableName}/{rowPrefix}")
  24. public ResponseVo scan(@PathVariable String tableName, @PathVariable String rowPrefix, @RequestParam(defaultValue = "100") Long size) {
  25. long start = System.currentTimeMillis();
  26. try {
  27. List<Object> scan = hbaseQueryService.scan(tableName, rowPrefix, size);
  28. return ResponseVo.success(start, scan);
  29. } catch (Exception e) {
  30. log.error(e.getMessage(), e);
  31. return ResponseVo.failure(start, e.getMessage());
  32. }
  33. }
  34. @ApiOperation(value = "点查")
  35. @GetMapping("get/{tableName}/{rowkey}")
  36. public ResponseVo get(@PathVariable String tableName, @PathVariable String rowkey) {
  37. long start = System.currentTimeMillis();
  38. try {
  39. Object columnMap = hbaseQueryService.get(tableName, rowkey);
  40. return ResponseVo.success(start, columnMap);
  41. } catch (Exception e) {
  42. log.error(e.getMessage(), e);
  43. return ResponseVo.failure(start, e.getMessage());
  44. }
  45. }
  46. }