我已经编写了遍历多个实体的查询,并希望将其转换为独立的条件查询。不确定如何对多个表进行操作
StringBuilder queryString = new StringBuilder("from ");
queryString.append(Entity).append(" e where e.specificationId in (:ids)
and not exists ( select 1 from Association a where "
+ "a.sourceReference = e.reference )").append("order by
e.displayOrder");
答案 0 :(得分:0)
您可以使用Spring JPA。
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for drive.permissions.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.metadata https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/drive.photos.readonly https://www.googleapis.com/auth/drive.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/drive/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function updatePermission(fileId, permissionId, newRole) {
var newRole = "owner";
// First retrieve the permission from the API.
var request = gapi.client.drive.permissions.get({
"fileId": "xxxxx",
'permissionId': "xxxxx",
});
request.execute(function(resp) {
resp.role = newRole;
var updateRequest = gapi.client.drive.permissions.update({
'fileId': "xxxxx",
'permissionId': "xxxxx",
'resource': resp
});
updateRequest.execute(function(resp) {
});
});
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "xxx"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="updatePermission()">execute</button>
您将为每种类型创建一个接口并实现GenericRepository。
Ex:
@NoRepositoryBean
public interface GenericRepository<T extends Content<T>> extends JpaRepository<T, Long>
@Query("select e from #{#entityName} e where e.specificationId in (?) and not exists ( select 1 from Association a where a.sourceReference = e.reference ) order by e.displayOrder", nativeQuery=true)
public void T findByIds(List<Long> ids);
引用:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/