Java源码示例:org.springframework.data.querydsl.binding.QuerydslPredicate

示例1
/**
 * Obtains the domain type information from the given method parameter. Will
 * favor an explicitly registered on through
 * {@link QuerydslPredicate#root()} but use the actual type of the method's
 * return type as fallback.
 * 
 * @param parameter
 *            must not be {@literal null}.
 * @return
 */
static TypeInformation<?> extractTypeInfo(MethodParameter parameter) {

	QuerydslPredicate annotation = parameter.getParameterAnnotation(QuerydslPredicate.class);

	if (annotation != null && !Object.class.equals(annotation.root())) {
		return ClassTypeInformation.from(annotation.root());
	}

	Class<?> containingClass = parameter.getContainingClass();
	if (ClassUtils.isAssignable(EntityController.class, containingClass)) {
		ResolvableType resolvableType = ResolvableType.forClass(containingClass);
		return ClassTypeInformation.from(resolvableType.as(EntityController.class).getGeneric(0).resolve());
	}

	return detectDomainType(ClassTypeInformation.fromReturnTypeOf(parameter.getMethod()));
}
 
示例2
/**
 * Extract qdsl bindings querydsl bindings.
 *
 * @param predicate the predicate
 * @return the querydsl bindings
 */
private QuerydslBindings extractQdslBindings(QuerydslPredicate predicate) {
	ClassTypeInformation<?> classTypeInformation = ClassTypeInformation.from(predicate.root());
	TypeInformation<?> domainType = classTypeInformation.getRequiredActualType();

	Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = Optional.of(predicate)
			.map(QuerydslPredicate::bindings)
			.map(CastUtils::cast);

	return bindingsAnnotation
			.map(it -> querydslBindingsFactory.createBindingsFor(domainType, it))
			.orElseGet(() -> querydslBindingsFactory.createBindingsFor(domainType));
}
 
示例3
/**
 * GET  /connections/all : get all the connections.
 *
 * @param predicate predicate
 * @return the ResponseEntity with status 200 (OK) and the list of connections in body
 */
@GetMapping("/connections/all")
@Timed
public ResponseEntity<List<ConnectionDTO>> getAllConnections(@QuerydslPredicate(root = Connection.class) Predicate predicate) {
    log.debug("REST request to get a page of Connections");
    return new ResponseEntity<>(connectionService.findAll(predicate), HttpStatus.OK);
}
 
示例4
@GetMapping("/simplified")
public Page<Person> getPersonsSimplified(
		@QuerydslPredicate(root = Person.class) Predicate predicate, 
		@RequestParam(name = "page", defaultValue = "0") int page,
		@RequestParam(name = "size", defaultValue = "500") int size) {

	return personRepository.findAll(predicate, PageRequest.of(page, size, Sort.by(Sort.Direction.ASC, "id")));
}
 
示例5
@ApiOperation(value = "获取全部菜单", notes = "获取全部菜单,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResMenu>> getItems(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                            @RequestParam(value = "size", defaultValue = "15") Integer size,
                                            @QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return menuService.getMenus(-1, pageable, predicate);
}
 
示例6
@ApiOperation(value = "获取角色未授权菜单", notes = "获取角色未授权菜单,系统管理员默认可以访问")
@RequestMapping(value = "/getRoleNoMenu/{role_id}", method = RequestMethod.GET)
public BaseResponse<List<ResMenu>> getRoleNoMenu(@PathVariable("role_id") Long pkRole,
                                                 @RequestParam(value = "page", defaultValue = "0") Integer page,
                                                 @RequestParam(value = "size", defaultValue = "15") Integer size,
                                                 @QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return menuService.getRoleNoMenu(pkRole, -1L, pageable, predicate);
}
 
示例7
@ApiOperation(value = "获取全部角色,分页查询", notes = "获取全部角色,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResRole>> getItems(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                            @RequestParam(value = "size", defaultValue = "15") Integer size,
                                            @QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return roleService.getRoles(-1, pageable, predicate);
}
 
示例8
@ApiOperation(value = "获取组织信息", notes = "获取组织基本信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResGroup>> getGroupList(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                                 @RequestParam(value = "size", defaultValue = "15") Integer size,
                                                 @QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return groupService.getGroupList(pageable, predicate);
}
 
示例9
@ApiOperation(value = "获取用户信息", notes = "获取系统用户信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResUser>> getUser(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "15") Integer size,
                                           @QuerydslPredicate(root = SuperbootUser.class) Predicate user, @QuerydslPredicate(root = SuperbootRole.class) Predicate role, @QuerydslPredicate(root = SuperbootGroup.class) Predicate group) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return userService.getUserList(pageable, false, user, role, group);
}
 
示例10
@ApiOperation(value = "获取日志列表信息", notes = "获取日志列表信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResLog>> getLogList(@QuerydslPredicate(root = DataInfo.class) Predicate predicate, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                             @RequestParam(value = "size", defaultValue = "15") Integer size) throws BaseException {
    //添加排序 默认按照最后访问时间进行倒排
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "execTime"));
    Pageable pageable = new PageRequest(page, size, sort);
    return service.getLogList(pageable, predicate);
}
 
示例11
@ApiOperation(value = "获取日志列表信息", notes = "获取日志列表信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResErrLog>> getErrorLogList(@QuerydslPredicate(root = ErrorInfo.class) Predicate predicate, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                                     @RequestParam(value = "size", defaultValue = "15") Integer size) throws BaseException {
    //添加排序 默认按照最后访问时间进行倒排
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "execTime"));
    Pageable pageable = new PageRequest(page, size, sort);
    return service.getErrorLogList(pageable, predicate);
}
 
示例12
/**
 * Another alternative to QBE via QueryDsl Predicates.
 *
 * @param predicate the Predicate to use to query with
 * @param pageable a Pageable to restrict results
 * @return A paged result of matching Patients
 */
@GetMapping("/search/predicate")
public Page<Patient> getPatientsByPredicate(
		@QuerydslPredicate(root = Patient.class) final Predicate predicate, final Pageable pageable) {
	Page<Patient> pagedResults = this.patientRepository.findAll(predicate, pageable);

	if (!pagedResults.hasContent()) {
		throw new NotFoundException(Patient.RESOURCE_PATH,
				"No Patients found matching predicate " + predicate);
	}

	return pagedResults;
}
 
示例13
@Override
public boolean supportsParameter(MethodParameter parameter) {

	if (Predicate.class.equals(parameter.getParameterType())) {
		return true;
	}

	if (parameter.hasParameterAnnotation(QuerydslPredicate.class)) {
		throw new IllegalArgumentException(
				String.format("Parameter at position %s must be of type Predicate but was %s.",
						parameter.getParameterIndex(), parameter.getParameterType()));
	}

	return false;
}
 
示例14
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, //
		@QuerydslPredicate(root = User.class) Predicate predicate, //
		@PageableDefault(sort = { "lastname", "firstname" }) Pageable pageable, //
		@RequestParam MultiValueMap<String, String> parameters) {

	ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest();
	builder.replaceQueryParam("page", new Object[0]);

	model.addAttribute("baseUri", builder.build().toUri());
	model.addAttribute("users", repository.findAll(predicate, pageable));

	return "index";
}
 
示例15
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
	if (operation.getParameters() == null) {
		return operation;
	}

	MethodParameter[] methodParameters = handlerMethod.getMethodParameters();

	int parametersLength = methodParameters.length;
	List<Parameter> parametersToAddToOperation = new ArrayList<>();
	for (int i = 0; i < parametersLength; i++) {
		MethodParameter parameter = methodParameters[i];
		QuerydslPredicate predicate = parameter.getParameterAnnotation(QuerydslPredicate.class);

		if (predicate == null) {
			continue;
		}

		QuerydslBindings bindings = extractQdslBindings(predicate);

		Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).map(Field::getName).collect(Collectors.toSet());

		Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
		//remove blacklisted fields
		Set<String> blacklist = getFieldValues(bindings, "blackList");
		fieldsToAdd.removeIf(blacklist::contains);

		Set<String> whiteList = getFieldValues(bindings, "whiteList");
		Set<String> aliases = getFieldValues(bindings, "aliases");

		fieldsToAdd.addAll(aliases);
		fieldsToAdd.addAll(whiteList);
		for (String fieldName : fieldsToAdd) {
			Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
			io.swagger.v3.oas.models.parameters.Parameter newParameter = buildParam(type, fieldName);

			parametersToAddToOperation.add(newParameter);
		}
	}
	operation.getParameters().addAll(parametersToAddToOperation);
	return operation;
}
 
示例16
@GetMapping("/test")
public ResponseEntity<?> sayHello2(@QuerydslPredicate(bindings = CountryPredicate.class, root = Country.class) Predicate predicate,
		@RequestParam List<Status> statuses) {
	return ResponseEntity.ok().build();
}
 
示例17
@ApiOperation(value = "获取全部组织信息", notes = "获取全部组织信息,主要用于下拉使用")
@RequestMapping(value = "/group/all", method = RequestMethod.GET)
public BaseResponse<List<ResGroup>> getGroupAll(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return pubService.getGroupAll(predicate);
}
 
示例18
@ApiOperation(value = "获取组织树", notes = "获取组织树,主要用于构造菜单使用")
@RequestMapping(value = "/group/tree", method = RequestMethod.GET)
public BaseResponse<List<ResTree>> getGroupTree(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return pubService.getGroupTree(predicate);
}
 
示例19
@ApiOperation(value = "获取菜单总数", notes = "获取菜单总数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    return menuService.getCount(-1, predicate);
}
 
示例20
@ApiOperation(value = "获取记录总数", notes = "获取全部角色,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    return roleService.getCount(-1, predicate);
}
 
示例21
@ApiOperation(value = "获取全部角色", notes = "获取全部角色多用于下拉,系统管理员默认可以访问")
@RequestMapping(value = "/all", method = RequestMethod.GET)
public BaseResponse<List<ResRole>> getAll(@QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    return roleService.getRoleAll(-1, predicate);
}
 
示例22
@ApiOperation(value = "获取组织记录总数", notes = "获取组织记录总数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getGroupCount(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return groupService.getGroupCount(predicate);
}
 
示例23
@ApiOperation(value = "获取用户信息", notes = "获取系统用户信息,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootUser.class) Predicate user, @QuerydslPredicate(root = SuperbootRole.class) Predicate role, @QuerydslPredicate(root = SuperbootGroup.class) Predicate group) throws BaseException {
    return userService.getUserCount(user, role, group);
}
 
示例24
@ApiOperation(value = "获取日志记录数", notes = "获取日志记录数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getLogCount(@QuerydslPredicate(root = DataInfo.class) Predicate predicate) throws BaseException {
    return service.getLogCount(predicate);
}
 
示例25
@ApiOperation(value = "获取日志记录数", notes = "获取日志记录数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getErrorLogCount(@QuerydslPredicate(root = ErrorInfo.class) Predicate predicate) throws BaseException {
    return service.getErrorLogCount(predicate);
}
 
示例26
@GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<User> queryOverUser(@QuerydslPredicate(root = User.class) Predicate predicate) {
    final BooleanBuilder builder = new BooleanBuilder();
    return personRepository.findAll(builder.and(predicate));
}
 
示例27
@GetMapping(value = "/addresses", produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Address> queryOverAddress(@QuerydslPredicate(root = Address.class) Predicate predicate) {
    final BooleanBuilder builder = new BooleanBuilder();
    return addressRepository.findAll(builder.and(predicate));
}
 
示例28
@RequestMapping(method = RequestMethod.GET, value = "/api/myusers")
@ResponseBody
public Iterable<MyUser> findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) {
    return myUserRepository.findAll(predicate);
}
 
示例29
@GetMapping("/filteredusers")
public Iterable<User> getUsersByQuerydslPredicate(@QuerydslPredicate(root = User.class) Predicate predicate) {
    return userRepository.findAll(predicate);
}