实现类似于新浪微博的@功能

与前一篇的类似,这里增加的是把替代的百度链接换成自己项目的URL,如下:
String owner;
while (matcher.find()) {
// 取出@的用户名
owner = matcher.group().split("@")[1];//使用@作为分隔符,来获取用户名
// 判断所@的用户是否存在
boolean temp = userProfileService.isUserExist(owner);
if (temp) {
matcher.appendReplacement(sbuf,"<a href=\"" + path + "/userprofile/" + owner + "/edit" + "\" target=\"_blank\"><font color=\"#3333FF\">" + matcher.group() + "</font></a>");
}
}
matcher.appendTail(sbuf);
content = sbuf.toString();

在Action中通过 request.getContextPath() 获取当前URL

你可能感兴趣的:(实现类似于新浪微博的@功能)