1、设置接收上一篇下一篇的实体对象
/**
* 上一篇 下一篇的实体接收
* @author sl
* @since -01-05
*/
public class PreAndNextEntity {
/**
* 上一篇或者下一篇的id
*/
private String id;
/**
* 上一篇或者下一篇的标题
*/
private String title;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
2、根据所点击的一篇内容的id以及文章类型查询,该类型的文章的上一篇及下一篇的PreAndNextEntity实体内容
/**
* 获取上一篇的详细信息
* @return
* @throws BusinessMsgException
*/
public PreAndNextEntity getPreEntity(String middleId,String type) throws BusinessMsgException{
log.info("详细信息页面中上一篇显示 start");
PreAndNextEntity pre = new PreAndNextEntity();
PinPaiZiXunData pd = new PinPaiZiXunData();
String preid = "";
List<PinPaiZiXunData> list = new ArrayList<PinPaiZiXunData>();
list = PinPaiZiXunService.findDataByType(type);
int count = list.size();
//所有该类型的id存放数组
String [] strid = new String [count];
for(int i=0; i<count; i++){
strid[i] = list.get(i).getId();
}
for(int j=0; j<count; j++){
if(strid[j].equals(middleId)){
if(j != 0) preid = strid[j-1];
}
}
if("".equals(preid)){
pre.setId("");
pre.setTitle("没有了");
}else{
pd = PinPaiZiXunService.findDataByID(preid);
pre.setId(preid);
pre.setTitle(pd.getTitlecn());
}
log.info("详细信息页面中上一篇显示 end");
return pre;
}
/**
* 获取下一篇的详细信息
* @return
* @throws BusinessMsgException
*/
public PreAndNextEntity getNextEntity(String middleId,String type) throws BusinessMsgException{
log.info("详细信息页面中下一篇显示 start");
PreAndNextEntity next = new PreAndNextEntity();
PinPaiZiXunData pd = new PinPaiZiXunData();
String nextid = "";
List<PinPaiZiXunData> list = new ArrayList<PinPaiZiXunData>();
list = PinPaiZiXunService.findDataByType(type);
int count = list.size();
//所有该类型的id存放数组
String [] strid = new String [count];
for(int i=0; i<count; i++){
strid[i] = list.get(i).getId();
}
for(int j=0; j<count; j++){
if(strid[j].equals(middleId)){
if(j != count-1) nextid = strid[j+1];
}
}
if("".equals(nextid)){
next.setId("");
next.setTitle("没有了");
}else{
pd = PinPaiZiXunService.findDataByID(nextid);
next.setId(nextid);
next.setTitle(pd.getTitlecn());
}
log.info("详细信息页面中下一篇显示 end");
return next;
}
3、上一篇及下一篇的id及title传递到前台页面,成功后返回前台页面
public String showDetail() throws BusinessMsgException{
data = PinPaiZiXunService.findDataByID(id);
PreAndNextEntitypre = getPreEntity(id, data.getType());//上一篇内容
PreAndNextEntitynext = getNextEntity(id, data.getType());//下一篇内容
return SUCCESS;
}