Môi trường:mùa xuân-dữ liệu MongoDB truy vấn đánh chặn và tiêm ngữ hoặc đặc điểm kỹ thuật
mùa xuân-data-Mông Cổ: 1.7.0.RC1
Mongo-java-lái xe: 3.2.2
Document:
@Document(collection = "products")
public class Product {
@Id
private String sid;
private String name;
private Long vendor;
(...)
}
Repository :
public interface ProductRepository extends MongoRepository<Product, String> {
Product findByName(String productName);
}
My goa l là chặn bất kỳ truy vấn nào được thực hiện trên Bộ sưu tập sản phẩm và thêm một vị từ hoặc một đặc tả mà không cần sửa đổi kho lưu trữ hoặc cần phải thực hiện phương thức findByNameAndBelongsToVendorList.
tôi cần đánh chặn này hoặc AspectJ bởi vì tôi có nhiều phương pháp như:
Page<Product> findAll(Pageable page);
List<Product> findByCategory(String category, Pageable pageRequest);
(...)
Goal
findByName // perform a filter by name (explicit)
// and a filter by vendor (injected via inteceptor or aspecJ)
Tránh làm điều này
@Repository
public class ProductRepositoryCustomImpl implements ProductRepositoryCustom {
@Autowired
private MongoTemplate template;
public Product findByNameAndBelongsToVendorList(String name, List<Long> vendors, Pageable pageRequest) {
Criteria criteriaVendor = Criteria.where("vendors").in(vendors);
Query query = new Query(criteriaVendor);
query.with(pageRequest);
return template.findOne(query, Product.class);
}
}
Hiện tại tôi đang sử dụng 2 khung công tác ... SpringData e MongoTemplate. Với MongoTemplate tôi có thể sử dụng một dấu chấm trên * org.springframework.data.mongodb.core * và chặn tất cả các phương thức như findAll, findOne ... nhưng với SpringData tôi chưa biết cách thực hiện điều đó. – Leonel