简体   繁体   English

在Apache CXF中以编程方式创建排除参数?

[英]Programatically create exclusion parameters in Apache CXF?

I'm building a RESTful web service that queries a database using a QueryCriteria object. 我正在构建一个RESTful Web服务,该服务使用QueryCriteria对象查询数据库。 QueryCriteria has fields like 'color' and 'shape.' QueryCriteria具有“颜色”和“形状”等字段。

Right now I have an endpoint that binds query params to this query criteria object, eg 现在,我有一个将查询参数绑定到此查询条件对象的端点,例如

public String getObject(@Context final HttpServletRequest httpRequest_, 
@QueryParam("") final QueryCriteria criteria){
...
}

I want to be able to query for color!=Blue. 我希望能够查询颜色!=蓝色。 However, the only way I can think of doing this is, for every field in QueryCriteria, having an exclusion field, eg excludeColor, excludeShape. 但是,我想到的唯一方法是,对于QueryCriteria中的每个字段,都有一个排除字段,例如excludeColor,excludeShape。

This will add a lot of bloat to my criteria objects, is there a more elegant solution to my problem? 这将给我的标准对象增加很多膨胀,是否有更优雅的解决方案?

Answer: 回答:

OK, here is one solution I thought of. 好的,这是我想到的一种解决方案。

For each field, make two setters, eg setExcludeColor and setColor. 对于每个字段,进行两个设置器,例如setExcludeColor和setColor。 Both will modify a Pair, where the Left of the pair is what to include and the right is what to exclude. 两者都将修改一个对,其中对的左边是要包括的对,右边是要排除的对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM