使用Elasticsearch Data的Springboot为特定实体禁用REST端点

时间:2019-09-02 21:26:23

标签: spring-boot elasticsearch

我正在使用Elasticsearch数据和Springboot。看起来Springboot公开了我资源的所有REST端点。例如,我的索引模式是“订单”

当我尝试请求“ / orders”时,它返回以下内容:

{
  "_embedded": {
    "orders": [
      {
        "order_id": "adafagagagaga,
        "category": "test",
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/orders/adafagagagaga"
          },
          "order": {
            "href": "http://localhost:8080/api/orders/adafagagagaga"
          }
        }
      },
      ...
    ]
  },
  "_links": {
    "first": {
      "href": "http://localhost:8080/api/orders?page=0&size=20"
    },
    "self": {
      "href": "http://localhost:8080/api/orders{?page,size,sort}",
      "templated": true
    },
    "next": {
      "href": "http://localhost:8080/api/orders?page=1&size=20"
    },
    "last": {
      "href": "http://localhost:8080/api/orders?page=652&size=20"
    },
    "profile": {
      "href": "http://localhost:8080/api/profile/orders"
    },
    "search": {
      "href": "http://localhost:8080/api/orders/search"
    }
  },
  "page": {
    "size": 20,
    "totalElements": 13059,
    "totalPages": 653,
    "number": 0
  }
}

我的订单类

@Document(indexName="orders", type="_doc")
public class Order {
}

OrderRepository类

@Repository
public interface OrderRepositoy extends ElasticsearchRepository<Order, String> {    
    Page<Order> findAll(Pageable pageable);
}

OrderController

@RestController
@RequestMapping("/orders")
public class OrderController extends BaseController {

    @Autowired
    private OrderServiceImpl orderServiceImpl;

    @RequestMapping(value = {"/", "/page/{page}"})
    public Page<Order> findAll(@PathVariable Optional<Integer> page) throws Exception {

        int pageNum = page.isPresent() && page.get() == 0 ? 0 : page.get();
        return orderServiceImpl.findAll(PageRequest.of(pageNum, 5));
    }
}

OrderServiceImpl类

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderRepositoy orderRepository;

    @Autowired
    public void setOrderRepository(OrderRepositoy orderRepository) {
        this.orderRepository = orderRepository;
    }

    @Override
    public Page<Order> findAll(Pageable pageable) {
        return orderRepository.findAll(pageable);
    }
}

如何禁用此端点?我想使用Pageable代替它。

0 个答案:

没有答案