Integer id = WebUtil.StrToInt(Struts2Utils.getParameter("id"));//channel
String ctp = (String)(Struts2Utils.getRequest().getContextPath());//ctp
String title = Struts2Utils.getParameter("title");
int page =WebUtil.StrToInt(Struts2Utils.getParameter("page"));//channel.ftl传递过来的page的值
Channel channel = entityService.find(id);
Struts2Utils.setAttribute("entity", channel);
Struts2Utils.setAttribute("title", title);
Map <String,Object>map = new HashMap<String,Object>();
String channelFTL = "channel.html";
String singleFTL="single.html";
String relaPath ="";
String htmlName = id+".html";
map.put("entity", channel);
map.put("title", title);
try{
channel.setVisitTotal(channel.getVisitTotal()+1);//点击量加1
}catch(Exception e){
return "errorPage";
}
if(channel.getCheckState()==CheckState.pass)
{
if(channel.getSingle()!=null&&channel.getSingle()==true){
try {
new CreateHtml().init(singleFTL, htmlName, map, relaPath);//生成静态HTML
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}
else{
PageView<Article> pageView = new PageView<Article>(1);
if(page!=0){
pageView.setCurrentpage(page);
relaPath="Channel/";
htmlName=id+"_"+page+".html";//有页码的HTML的名称
}
int firstindex = (pageView.getCurrentpage()-1)*pageView.getMaxresult();
LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
orderby.put("id", "desc");
StringBuffer jpql = new StringBuffer("o.checkState=?1");
List<Object> params = new ArrayList<Object>();
params.add(CheckState.pass);
if(id!=null&&id!=1){
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.channel=?").append((params.size()+1));
params.add(new Channel(id));
}
if(title!=null && !"".equals(title)){
if(params.size()>0) jpql.append(" and ");
jpql.append(" o.title like ?").append((params.size()+1));
params.add("%"+ title+ "%");