1
每篇文章有三篇評論;評論具有「批准」欄(true表示評論接受文章,false表示拒絕)。如何選擇有兩個或更多批准的評論的文章?JPA查詢,選擇兩篇或兩篇以上批准評論的文章
mysql> describe article;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| content | longtext | NO | | NULL | |
| author_id | int(11) | NO | MUL | NULL | |
+--------------+--------------+------+-----+---------+----------------+
mysql> describe review;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| comment | varchar(255) | YES | | NULL | |
| approved | tinyint(1) | YES | | NULL | |
| article_id | int(11) | YES | MUL | NULL | |
| reviewer_id | int(11) | YES | MUL | NULL | |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
在這裏,我想使用JPA Reporsitory查詢:
public interface ArticleRepository extends JpaRepository<Article, Integer>{
@Query("XXXXXXXXXXXXXX")
public List<Article> findApprovedArticles();
}