本文整理汇总了Java中org.springframework.data.repository.CrudRepository.findOne方法的典型用法代码示例。如果您正苦于以下问题:Java CrudRepository.findOne方法的具体用法?Java CrudRepository.findOne怎么用?Java CrudRepository.findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.repository.CrudRepository
的用法示例。
在下文中一共展示了CrudRepository.findOne方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasPermission
import org.springframework.data.repository.CrudRepository; //导入方法依赖的package包/类
@Override
public boolean hasPermission(@NotNull Authentication authentication,
@NotNull Serializable serializable,
@NotNull String className,
@NotNull Object permissions) {
boolean result = false;
CrudRepository<Object, Serializable> repository = repositoryFinder.find(className);
if (repository != null) {
Object targetDomainObject = repository.findOne(serializable);
if (targetDomainObject instanceof CreatorAware) {
result = hasPermission(authentication, targetDomainObject, permissions);
} else if (targetDomainObject == null) {
result = true;
}
}
return result;
}
示例2: shouldFindOne
import org.springframework.data.repository.CrudRepository; //导入方法依赖的package包/类
@Test
public void shouldFindOne() throws Exception {
CrudRepository<T, UUID> repository = this.getRepository();
T instance = this.generateInstance();
instance = repository.save(instance);
assertInstance(instance);
UUID id = instance.getId();
instance = repository.findOne(id);
assertInstance(instance);
Assert.assertEquals(id, instance.getId());
}
示例3: safeGet
import org.springframework.data.repository.CrudRepository; //导入方法依赖的package包/类
private <T extends ContentEntity> T safeGet(ContentDto s, CrudRepository<? extends T, UUID> repo, T newEntity) {
try {
T entity = repo.findOne(s.getId());
return entity;
} catch (Exception e) {
return newEntity;
}
}
示例4: addACLUserGeneric
import org.springframework.data.repository.CrudRepository; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.POST, value = "/acl/user/generic/")
public @ResponseBody HttpEntity<List<String>> addACLUserGeneric(
@RequestBody UserACLRequestSet aclSet) {
List<String> result = new ArrayList<String>();
try {
SecurityACLDAO securityACLDAO = beanFactory.getBean(
Constants.SECURITYACL_DAO, SecurityACLDAO.class);
logger.debug("entityList size:" + aclSet.getAclList().size());
String entityId = null;
for (UserACLRequest acl : aclSet.getAclList()) {
entityId = acl.getEntityId();
String repoName = classToRepoMap.get(acl.getEntityClassName());
CrudRepository repo = getRepo(repoName);
AbstractSecuredEntity securedEntity = (AbstractSecuredEntity) repo
.findOne(Long.parseLong(entityId));
if (securedEntity == null) {
result.add("Entity of type " + acl.getEntityClassName()
+ " with id " + acl.getEntityId() + " not found");
continue;
}
UserEntity userEntity = userEntityRepo.findByUsername(acl
.getUserName());
if (userEntity == null) {
result.add("User " + acl.getUserName() + " not found");
continue;
}
boolean res = securityACLDAO.addAccessControlEntry(
securedEntity,
new PrincipalSid(userEntity.getUsername()),
getPermissionFromNumber(acl.getPermission()));
if (res) {
// on sucess don't add msg to result list
logger.debug("Added ACL for:" + acl.toString());
} else {
result.add("Failed to add ACL for:" + acl.toString());
}
}
} catch (Exception e) {
logger.warn("", e);
result.add("Exception:" + e.getMessage());
}
if (result.isEmpty()) {
result.add("Successfully added all ACLs");
return new ResponseEntity<List<String>>(result, HttpStatus.OK);
} else {
return new ResponseEntity<List<String>>(result, HttpStatus.OK);
}
}
示例5: removeACLUserGeneric
import org.springframework.data.repository.CrudRepository; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.DELETE, value = "/acl/user/generic/")
public @ResponseBody HttpEntity<List<String>> removeACLUserGeneric(
@RequestBody UserACLRequestSet aclSet) {
List<String> result = new ArrayList<String>();
try {
SecurityACLDAO securityACLDAO = beanFactory.getBean(
Constants.SECURITYACL_DAO, SecurityACLDAO.class);
logger.debug("entityList size:" + aclSet.getAclList().size());
String entityId = null;
for (UserACLRequest acl : aclSet.getAclList()) {
entityId = acl.getEntityId();
String repoName = classToRepoMap.get(acl.getEntityClassName());
CrudRepository repo = getRepo(repoName);
AbstractSecuredEntity securedEntity = (AbstractSecuredEntity) repo
.findOne(Long.parseLong(entityId));
if (securedEntity == null) {
result.add("Entity of type " + acl.getEntityClassName()
+ " with id " + acl.getEntityId() + " not found");
continue;
}
UserEntity userEntity = userEntityRepo.findByUsername(acl
.getUserName());
if (userEntity == null) {
result.add("User " + acl.getUserName() + " not found");
continue;
}
boolean res = securityACLDAO.deleteAccessControlEntry(
securedEntity,
new PrincipalSid(userEntity.getUsername()),
getPermissionFromNumber(acl.getPermission()));
if (res) {
// on sucess don't add msg to result list
logger.debug("Deleted ACL for:" + acl.toString());
} else {
result.add("Failed to add ACL for:" + acl.toString());
}
}
} catch (Exception e) {
logger.warn("", e);
result.add("Exception:" + e.getMessage());
}
if (result.isEmpty()) {
result.add("Successfully deleted all ACLs");
return new ResponseEntity<List<String>>(result, HttpStatus.OK);
} else {
return new ResponseEntity<List<String>>(result, HttpStatus.OK);
}
}