[英]Object to Rest-URL
The user can set a number of values (which are optional) for a search query that will be passed on to a REST api. 用户可以为搜索查询设置许多值(可选),这些值将传递给REST api。 So I create a POJO to hold all the set values like
所以我创建了一个POJO来保存所有设置值,例如
class Search{
private String minPrice;
private String maxPrice;
private String category;
// etc.pp.
}
When I construct the URL for the api call, i have to check wether that value is set all the time like 当我为api调用构造URL时,我必须检查是否一直在设置该值,例如
if (search.getMinPrice() != null){
url.append("&minprice=" + search.getMinPrice());
}
Is there a more convenient/ elegant way to do this 有没有更方便/更优雅的方式来做到这一点
就像是:
String url = "http://base.com/some/path?" + (maxPrice==null ? "" : "maxPrice="+maxPrice);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.