linkoperimp.java
来自「jaguey,网上的一个朋友给我的」· Java 代码 · 共 108 行
JAVA
108 行
package net.javapassion.jaguey.service.imp;
import java.util.List;
import java.util.Iterator;
import net.javapassion.jaguey.core.Log;
import net.javapassion.jaguey.domain.Link;
import net.javapassion.jaguey.dao.LinkDao;
import net.javapassion.jaguey.service.LinkOper;
//版本: JagueyBBS 1.1
//功能: 论坛友情链接业务逻辑实现
//作者: 赵程佳
//时间: 2006-02-10 16:26:08
public class LinkOperImp implements LinkOper {
private LinkDao linkDao;
//保存友情链接
public String saveLink(Link link) {
try {
this.linkDao.saveLink(link);
return "success";
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "failed";
}
}
//删除友情链接
public String deleteLink(String id) {
try {
Link link = this.linkDao.getLinkById(id);
if (link != null) {
this.linkDao.deleteLink(link);
return "success";
} else {
return "can't find data";
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "failed";
}
}
//获取全部友情链接
public List getLinks() {
try {
return this.linkDao.getLinks();
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return null;
}
}
//通过友情链接编号获取友情链接
public Link getLinkById(String id) {
try {
return this.linkDao.getLinkById(id);
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return null;
}
}
//创建友情链接编号
public String makeLinkId() {
String linkId = "";
try {
List list = this.linkDao.getLinks();
if (list.size() == 0) {
return "000001";
} else {
Iterator it = list.iterator();
int i = 1;
while (it.hasNext()) {
if (i == list.size()) {
Link link = (Link) it.next();
linkId = String.valueOf(Integer.parseInt(link.getId()) + 1);
if (Integer.parseInt(linkId) != 1000000) {
switch (linkId.length()) {
case 1 : linkId = "00000" + linkId; break;
case 2 : linkId = "0000" + linkId; break;
case 3 : linkId = "000" + linkId; break;
case 4 : linkId = "00" + linkId; break;
case 5 : linkId = "0" + linkId; break;
}
} else {
Log.info("The linkId have already exceed to allow max quantity!");
linkId = "000000";
}
} else {
i++;
continue;
}
}
return linkId;
}
} catch (Exception ex) {
Log.error(ex.getMessage(), ex);
return "";
}
}
public void setLinkDao(LinkDao linkDao) {
this.linkDao = linkDao;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?