我需要在java spring中执行预构建的SQL查询,我创建的查询如下,
String query = "select * from device where";
if (status != null) {
query += " status = "+status;
}
if (cinema != "") {
query += " and cinema_code = \'"+cinema+"\'";
}
if (content_profile != "") {
query += " and content_profile = \'"+content_profile+"\'";
}
if (mac != "") {
query += " and mac = \'"+mac+"\'";
}
构建查询:
select *
from device
where status = 2
and cinema_code = 'AL10'
and content_profile = 'signage'
最佳答案
您可以使用 Spring Data JPA 规范进行动态查询。 看看这里: https://www.baeldung.com/rest-api-search-language-spring-data-specifications
关于java - 如何在 Java Spring 中执行预构建查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58218326/