本文整理匯總了Java中org.springframework.web.util.UriUtils.encodeQueryParam方法的典型用法代碼示例。如果您正苦於以下問題:Java UriUtils.encodeQueryParam方法的具體用法?Java UriUtils.encodeQueryParam怎麽用?Java UriUtils.encodeQueryParam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.util.UriUtils
的用法示例。
在下文中一共展示了UriUtils.encodeQueryParam方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getQueryString
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
private String getQueryString(ParticipantAddress address) {
int zip = address.getZip();
String cityName = address.getCityName();
String street = address.getStreet();
String streetNr = address.getStreetNr();
String result = streetNr + " " + street + ", " + zip;
if (StringUtils.isNotEmpty(cityName)) {
result += " " + cityName;
}
try {
result = UriUtils.encodeQueryParam(result, "UTF-8");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
示例2: searchSmartNames
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
private List<Result> searchSmartNames(SearchQuery query, String givenName, String familyName) throws Exception {
String q = String.format("given-names:%s AND family-name:%s", givenName, familyName);
String fields = createSearchFieldsQueryString(query);
if(fields.length() > 0) {
q += " " + fields;
}
String url = String.format("http://pub.orcid.org/v1.2/search/orcid-bio/?rows=%d&q=", query.getLimit()) +
UriUtils.encodeQueryParam(q, "UTF-8");
return doSearch(query, url);
}
示例3: search
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
@Override
public List<Result> search(SearchQuery query) throws Exception {
List<Result> results = new ArrayList<>();
int tries = 0;
// try twice, first with properties; if no results, try just the main search value
while(results.size() == 0 && tries < 2) {
String q = createQuery(query, tries == 0);
String url = "https://openlibrary.org/search.json?q=" + UriUtils.encodeQueryParam(q, "UTF-8");
getLog().debug("Making request to " + url);
HttpURLConnection conn = getConnectionFactory().createConnection(url);
JsonNode root = mapper.readTree(conn.getInputStream());
JsonNode docs = root.get("docs");
if(docs.isArray()) {
Iterator<JsonNode> iter = docs.iterator();
while(iter.hasNext() && results.size() < query.getLimit()) {
JsonNode doc = iter.next();
String title = doc.get("title").asText();
String key = doc.get("key").asText();
results.add(new Result(key, title, bookType, 1.0, false));
}
}
tries++;
}
return results;
}
示例4: buildURI
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
private URI buildURI(OTXEndpoints endpoint, Map<OTXEndpointParameters, ?> endpointParametersMap) throws URISyntaxException, MalformedURLException {
String endpointString = endpoint.getEndpoint();
if (endpointParametersMap != null) {
boolean first = true;
for (Map.Entry<OTXEndpointParameters, ?> otxEndpointParametersEntry : endpointParametersMap.entrySet()) {
if (otxEndpointParametersEntry.getKey().isRestVariable()) {
endpointString = endpointString.replace("{" + otxEndpointParametersEntry.getKey().getParameterName() + "}", otxEndpointParametersEntry.getValue().toString());
} else {
if (first) {
endpointString = endpointString + "?";
first = false;
}
try {
String parameterName = otxEndpointParametersEntry.getKey().getParameterName();
String value = UriUtils.encodeQueryParam(otxEndpointParametersEntry.getValue().toString(), "UTF-8");
endpointString = endpointString + String.format("%s=%s&", parameterName, value);
} catch (UnsupportedEncodingException e) {
log.error("Unpossible");
}
}
}
}
if (otxPort != null) {
return new URL(otxScheme, otxHost, otxPort, endpointString).toURI();
} else {
return new URL(otxScheme, otxHost, endpointString).toURI();
}
}
示例5: searchKeyword
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
protected List<Result> searchKeyword(SearchQuery query) throws Exception {
String q = createQueryString(query);
String url = String.format("http://pub.orcid.org/v1.2/search/orcid-bio/?rows=%d&q=", query.getLimit()) +
UriUtils.encodeQueryParam(q, "UTF-8");
return doSearch(query, url);
}
示例6: testUrlEncodePercentH
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
@Test
public void testUrlEncodePercentH() throws Exception {
String foo = UriUtils.encodeQueryParam("~1xwbccw58-43436_1", "UTF8");
assertThat(foo, is("~1xwbccw58-43436_1"));
}