我有这个表结构
tb_country
id | name
-------------------------------
1 | EUA
2 | FRANCE
3 | JAPAN
tb_cities
id | name | country_id | save
-------------------------------------------------
1 | CHICAGO | 1 | true
2 | NY | 1 | true
3 | SEATLE | 1 | false
4 | PARIS | 2 | true
5 | NICE | 2 | true
6 | TOKIO | 3 | true
7 | NAGOIA | 3 | false
所以我需要在创建的sql中用save = false
返回国家和城市:
"SELECT * FROM tb_country c1 JOIN tb_cities c2 ON c2.country_id = c1.id WHERE c2.save = false;
将仅返回
EUA -> SEATLE
JAPAN -> NAGOIA.
如果我将选择的内容放在HQL中
SELECT t FROM TbCountry c JOIN c.cities c2 WHERE c2.save = false;
他将返回该国家EUA和JAPAN,但他将返回该国的所有城市
如果我输入实体@Where(clause = "save = false ")
将仅返回SEATLE和NAGOIA,但是如果我需要更改该子句,该如何使它动态化?
tks