In Spring Data JPA, what does the method signature
4 phương ánCó giải thích
List<Entity> findByPropertyOrderByPropertyAsc(String property);do?
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "Finds entities where property is equal to String property, ordered by property ascending.". Spring Data JPA phân tích tên phương thức để sinh truy vấn: tiền tố findBy mở phần điều kiện, Property không đi kèm từ khoá nào nên mặc định là phép so sánh bằng với tham số String property, còn OrderByPropertyAsc thêm mệnh đề sắp xếp tăng dần theo chính thuộc tính đó; truy vấn tương đương là WHERE property = ?1 ORDER BY property ASC, trả về List các entity. "Finds entities where property is equal to String property, ordered by property descending." sai ở chiều sắp xếp, vì Asc là tăng dần, muốn giảm dần phải viết Desc. "Finds entities where property contains String property, ordered by property ascending." cần từ khoá Containing trong tên, như findByPropertyContaining, để sinh LIKE có ký tự đại diện hai đầu. "Finds entities where property is less than String property, ordered by property ascending." cần từ khoá LessThan, như findByPropertyLessThan.
Cùng phần 4
Xuất hiện trong 2 bộ đề
Đi tiếp từ đây