
在jdeveloper中,当使用web服务数据控件并将数据显示在页面片段的表格中时,开发者常面临一个挑战:如何根据特定属性过滤数据。尤其是在jdeveloper 12.2.1.3.0等版本中,web服务数据控件的配置页面可能不提供“命名条件”(named criteria)等直接的过滤选项,这使得在客户端直接应用声明式过滤变得困难。面对这种情况,主要有两种策略可以有效实现数据过滤。
最直接且通常效率最高的解决方案是在数据源层面,即Web服务本身,实现数据的过滤和排序。这种方法将过滤逻辑推送到服务器端,减少了网络传输的数据量,并减轻了客户端的处理负担。
实现方式:
优点:
注意事项:
当无法修改后端Web服务时,或者当需要更灵活、动态的客户端过滤逻辑时,可以在JDeveloper客户端获取所有数据后,将其加载到POJO(Plain Old Java Object)模型中,然后进行自定义的过滤和排序。
实现方式:
示例代码(概念性): 假设您有一个Employee POJO类,并且从Web服务获取了一个List<Employee>:
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class EmployeeFilterService {
public List<Employee> filterEmployees(List<Employee> allEmployees, String departmentFilter, double minSalary) {
if (allEmployees == null || allEmployees.isEmpty()) {
return new ArrayList<>();
}
List<Employee> filteredList = allEmployees.stream()
.filter(e -> departmentFilter == null || departmentFilter.isEmpty() || e.getDepartment().equalsIgnoreCase(departmentFilter))
.filter(e -> e.getSalary() >= minSalary)
.collect(Collectors.toList());
return filteredList;
}
// 假设 Employee 类如下
public static class Employee {
private String name;
private String department;
private double salary;
public Employee(String name, String department, double salary) {
this.name = name;
this.department = department;
this.salary = salary;
}
public String getName() { return name; }
public String getDepartment() { return department; }
public double getSalary() { return salary; }
// 其他getter/setter
}
public static void main(String[] args) {
List<Employee> employees = new ArrayList<>();
employees.add(new Employee("Alice", "HR", 60000));
employees.add(new Employee("Bob", "IT", 75000));
employees.add(new Employee("Charlie", "HR", 55000));
employees.add(new Employee("David", "IT", 80000));
EmployeeFilterService service = new EmployeeFilterService();
// 过滤部门为"IT"且薪资大于70000的员工
List<Employee> result = service.filterEmployees(employees, "IT", 70000);
result.forEach(e -> System.out.println(e.getName() + " - " + e.getDepartment() + " - " + e.getSalary()));
// 预期输出:
// Bob - IT - 75000.0
// David - IT - 80000.0
}
}在JDeveloper的ADF应用中,您可以在一个Managed Bean中调用Web服务获取数据,然后使用类似上述的逻辑对其进行过滤,并将过滤后的List<Employee>绑定到UI组件(如ADF表格)。
优点:
注意事项:
在JDeveloper中对Web服务数据控件进行过滤,尤其是在缺少直接过滤选项时,应根据实际情况选择合适的策略。优先考虑在Web服务后端实现过滤(策略一),这通常能带来最佳的性能和用户体验。如果后端修改不可行,或者需要极高的客户端灵活性,那么在客户端通过POJO模型进行自定义过滤(策略二)是一个可行的替代方案。在选择时,务必权衡数据量、性能要求、开发资源和维护成本等因素。
以上就是JDeveloper中Web服务数据控件的过滤策略的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号