📄 teacherlistaction.java
字号:
package com.comingnet.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.db.DBOperator;
import com.db.page;
import com.opensymphony.xwork2.ActionSupport;
public class TeacherListAction extends ActionSupport {
List teacherlist=null;
private String pageStr; //分页字符串
private String pageno; //当前页
private int pagecount=0; //总记录数
private int rownum=15; //每页记录数
private int pagerow=10; //显示多少页
private int xxbh=0;
public int getXxbh() {
return xxbh;
}
public void setXxbh(int xxbh) {
this.xxbh = xxbh;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public String getPageno() {
return pageno;
}
public void setPageno(String pageno) {
this.pageno=pageno;
}
public String getPageStr() {
return pageStr;
}
public void setPageStr(String pageStr) {
this.pageStr = pageStr;
}
public List getTeacherlist() {
return teacherlist;
}
public void setTeacherlist(List teacherlist) {
this.teacherlist = teacherlist;
}
public String execute()
{
String flag;
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
if(session.getAttribute("xxbh")==null){
flag=ERROR;
}else{
setXxbh(Integer.parseInt(session.getAttribute("xxbh").toString()));
}
String pageno1=getPageno(); //得到当前页
if(pageno1==null)
pageno1="1";
ArrayList list=null;
ArrayList list0=null;
ArrayList list1=null;
ArrayList list2=null;
List newlist=new ArrayList();
DBOperator dbop=new DBOperator();
try
{
System.out.println( "select count(*) from m_teacher where xxbh="+getXxbh());
list0=dbop.ExecuteSelect(false, "select count(*) from m_teacher where xxbh="+getXxbh());
if(list0.size()>0){
System.out.println(((ArrayList)list0.get(0)).get(0).toString());
pagecount=Integer.parseInt(((ArrayList)list0.get(0)).get(0).toString());
}
setPagecount(pagecount); //向前台传回总记录数
//System.out.println("xxbh-->"+xxbh);
page page1=new page();
page1.setPageString(pagecount,rownum,Integer.parseInt(pageno1),pagerow,"");
String pageStr=page1.getPageString();
setPageStr(pageStr); //设置分页的字符串
System.out.println(pageStr);
int cupage=Integer.parseInt(pageno1)-1;
String sqlStr="select top "+rownum+" jsid,jsxm,jsxb,jszh,jscsrq from m_teacher where xxbh="+getXxbh()+" and (jsid not in (select top "+cupage*15+" jsid from m_teacher order by jsid DESC)) order by jsid DESC";
System.out.println("sqlStr-->"+sqlStr);
list1=dbop.ExecuteSelect(true, sqlStr);
String name="";
String nameStr="js_xh";
int j=0;
HashMap row=null;
list2=(ArrayList) list1.get(0);
for(int i=1;i<list1.size();i++){
list=(ArrayList) list1.get(i) ;
j++;
row=new HashMap();
for(int k=0;k<list2.size();k++)
{
String temp=list.get(k).toString();
if(temp.contains("00:00:00.0")){
temp=list.get(k).toString().replace("00:00:00.0","");
}
name=list2.get(k).toString();
row.put(nameStr,""+j);
row.put(name.toLowerCase(),temp);
}
newlist.add(row);
}
setTeacherlist(newlist); //此处不能利用getList1(),get方法是获取从页面传过来的值
flag=SUCCESS;
}catch(Exception e)
{
flag=ERROR;
}
// System.out.println("flag-->"+flag);
return flag ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -