天天看点

java匿名对象作用_java匿名内部类使用场景列举

public interface LinkBuilder {

public StringBuffer getPagerUrl();

//public void setPage(int page);

public StringBuffer getPageUrl(int page);

}

public abstract class AbstractLinkBuilder implements LinkBuilder {

@Override

public final StringBuffer getPageUrl(int page) {

StringBuffer url = new StringBuffer(XssFilterService.dhtmlSpecialchars(

this.getPagerUrl(), true));

if (url.toString().indexOf("?") > 0) {

url.append("&");

} else {

url.append("?");

}

url.append("page=").append(page);

return url;

}

}

Pager pager = Pager.register("newPagerWidget",new AbstractLinkBuilder() {@Override

public StringBuffer getPagerUrl() {

StringBuffer url = null;

if (queryAgentStore != null) {

url = new StringBuffer("agentstorelist.html?");

if (StringUtils.isNotBlank(queryAgentStore

.getStoreName()))// 店铺关键字

{

url.append("&queryAgentStore.storeName="+ XssFilterService.dhtmlSpecialchars(queryAgentStore.getStoreName()));

}

if (queryAgentStore.getCity()!=null)// 城市编码

{

url.append("&queryAgentStore.city="+ queryAgentStore.getCity());

}

if(orderByClause!=null&&!"".equals(orderByClause))

{

url.append("&orderByClause="+orderByClause);

}

} else {

url = new StringBuffer("agentstorelist.html");

}

return url;

}

}, request);

public class Pager

{

public Pager(LinkBuilder builder) {

this.linkBuilder = builder;

}

public String getUrl(int page) {

return staticTool.process(this.linkBuilder.getPageUrl(page).toString());

}

}