1 回答

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個贊
您可以添加以下方法來設(shè)置優(yōu)先級:
public static String getPriority (String location){
switch(countSlashes(location)){
case 3: return "1";
case 4: return "0.9";
case 5: return "0.8";
case 6: return "0.7";
default: return "0.0"; //or whatever prio in default case
}
}
//replace everything except '/' to get count of slashes easily
private static int countSlashes(String location) {
return location.replaceAll("[^/]", "").length();
}
然后您可以getPriority從您的createXMLNode方法中調(diào)用,如下所示:
.....
String location = request.getScheme() + "://" + request.getServerName() + childPage.getPath();
locElementNode.setTextContent(location);
....
priorityElementNode.setTextContent(getPriority(location));
....
添加回答
舉報