package com.action; import com.bean.electric_addBean; import com.dao.electriDao; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.ServletActionContext; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.PrintWriter; import java.util.List; public class electricManager extends ActionSupport { //下面是Action内用于封装用户请求参数的属性 private List list; public List getList() { return list; } public void setList(List list) { this.list = list; } private String SearchRow; private String SearchKey; public String getSearchRow() { return SearchRow; } public void setSearchRow(String searchRow) { SearchRow = searchRow; } public String getSearchKey() { return SearchKey; } public void setSearchKey(String searchKey) { SearchKey = searchKey; } //处理用户请求的execute方法 public String execute() throws Exception { //解决乱码,用于页面输出 HttpServletResponse response = null; response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); //创建session对象 HttpSession session = ServletActionContext.getRequest().getSession(); //验证是否正常登录 if(session.getAttribute("id")==null){ out.print(""); out.flush();out.close();return null; } //查询条件 // String strWhere="1=1"; // if(!(isInvalid(SearchKey))) // { // strWhere+=" and "+SearchRow+"='"+SearchKey+"'"; // } // if(!(isInvalid(State))) // { // strWhere+=" and Student_State='"+State+"'"; // } // else // { // strWhere+=" and Student_State='入住'"; // } //查询所有 if(session.getAttribute("type").toString().equals("3")){ String strWhere = "1=1"; if (!(isInvalid(SearchKey))) { strWhere += " and " + SearchRow + "='" + SearchKey + "'"; } // if(!(isInvalid(Integer.toString(repair_id)))) // { // strWhere+=" and repair_id='"+repair_id+"'"; // } //查询所有楼宇 //list=new RepairDao().GetList("","repair_id"); //查询所有 list = new electriDao().GetList(strWhere, "Electric_Dormitory_Number"); return ERROR;} else{ String strWhere = "1=1"; if (!(isInvalid(SearchKey))) { strWhere += " and " + SearchRow + "='" + SearchKey + "'"; } // if(!(isInvalid(Integer.toString(repair_id)))) // { // strWhere+=" and repair_id='"+repair_id+"'"; // } //查询所有楼宇 //list=new RepairDao().GetList("","repair_id"); //查询所有 list = new electriDao().GetList(strWhere, "Electric_Dormitory_Number"); return SUCCESS; }} //判断是否空值 private boolean isInvalid(String value) { return (value == null || value.length() == 0); } //测试 public static void main(String[] args) { System.out.println(); } }