//NewAtion
private New news;
private NewControl ne;
private String tip;
private List<New> newlist;
private int id;
private int pageIndex=1;
private int pageSize=5;
private int total_news;
private int total;
private int state=0;//状态
/**
* 查询用户集合* @return 结果字符串
*/
public String showList(){
select();
selectotal();
newlist = ne.getPageList(pageSize,pageIndex);
if (null!=newlist && newlist.size()>=1) {
return "showlist";
}else {
return "error";
}
}
/**
* 页码
* @return
*/
public String selectotal(){
select();
if (total_news%5==0) {
total=total_news/pageSize;
} else {
total=total_news/pageSize+1;
}
return "total";
}
/**
* 总数据
* @return
*/
public String select(){
total_news=ne.getNewsCount();
return "total_news";
}
/**
* 进入回收站新闻
* @return dispat
* @throws SQLException
*/
public String delete() throws SQLException{
int num = ne.updateclear(id);
if (num >= 1) {
showList();
return "showlist";
} else {
return "error";
}
}
/**
* 还原新闻
* @return dispat
* @throws SQLException
*/
public String updatestate() throws SQLException{
int num = ne.updatenews(id);
if (num >= 1) {
showclear();
return "showlist";
} else {
return "error";
}
}
/**
* 新闻彻底删除
* @return
* @throws SQLException
*/
public String updatenew() throws SQLException {
String dispat="";
int num=ne.deleteNew(id);
if (num>=1) {
showclear();
dispat="showlist";
}else {
dispat="error";
}
return dispat;
}
/**
* 查询用户集合
* @return 结果字符串
*/
public String showclear(){
select();
selectotal();
newlist = ne.getdelete(pageSize,pageIndex);
return "showlist";
}
//jsp
<div class="tablelist">
<table class="table">
<tr>
<th colspan="8" class="top_th"><a href="<%=path %>/back-stage_new.jsp" class="add"><em>添加</em><span></span></a><a href="system/showListNewAction.action?state=0" class="edit"><em>全部</em><span></span></a><a href="#" class="tongji"><em>统计</em><span></span></a><a class="sort" href="system/showclearNewAction.action?id=<s:property value="nid" />&state=1"><em>回收</em><span></span></a></th>
</tr>
<tr>
<th>编号</th><th>标题</th><th>摘要</th><th>日期</th><th>操作</th>
</tr>
<s:iterator value="newlist">
<tr>
<td><s:property value="nid"/></td><td><s:property value="ntitle"/></td>
<td><s:property value="nsumment" />
</td>
<td><s:property value="ndate" />
</td>
<c:if test="${state==0 }">
<td width="60">
<a id="operate" href="system/showNewAction.action?id=<s:property value="nid" />">修改</a>
</td>
<td width="60"><a
href="system/deleteNewAction.action?id=<s:property value="nid" />"
id="operate" οnclick="return del()">删除</a>
</td>
</c:if>
<c:if test="${state==1 }">
<td width="60">
<a id="operate" href="system/updatestateNewAction.action?id=<s:property value="nid" />&state=1">还原</a>
</td>
<td width="60"><a
href="system/updatenewNewAction.action?id=<s:property value="nid" />&state=1"
id="operate" οnclick="return del()">删除</a>
</td>
</c:if>
</tr>
</s:iterator>
<c:if test="${ newlist==null }">
<tr><td>查询不到数据</td></tr>
</c:if>
</table>
</div>
//Struts2
<action name="*NewAction" class="com.bookshop.system.action.NewAction" method="{1}">
<result name="success" type="redirect">/index.jsp</result>
<result name="error" type="redirect">/error.jsp</result>
<result name="login" type="dispatcher">/{1}.jsp</result>
<result name="showlist" >/back-stage_newpage.jsp</result>
<result name="show" >/back-stage_newupdate.jsp</result>
<result name="list" type="redirectAction">showListNewAction</result>
</action>