📄 useraction.java
字号:
package com.hisoft.cottonbusiness.action;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import com.hisoft.cottonbusiness.core.action.BaseAction;
import com.hisoft.cottonbusiness.core.common.ListWrapper;
import com.hisoft.cottonbusiness.core.common.PageInfo;
import com.hisoft.cottonbusiness.core.common.PageInputCollector;
import com.hisoft.cottonbusiness.core.common.ServiceLocator;
import com.hisoft.cottonbusiness.core.util.RequestParamUtil;
import com.hisoft.cottonbusiness.service.UserBO;
/**
* 该类负责所有和用户相关的操作
*
* @author chen_zhiwu
*
*/
public class UserAction extends BaseAction
{
private static final Logger log = Logger.getLogger(UserAction.class);
private UserBO userBO = (UserBO) ServiceLocator.getBean("userBO");
private static final String PAGE_CREATE_USER = "createUser";
private static final String ROOT_ELEMENT = "cncotton";
/**
* 初始化用户创建页面
*
* @return
* @throws Exception
*/
public String createUser() throws Exception
{
Map result = userBO.initCreateUser();
List listRole = (List) result.get("listRole");
mapOut.put("listRole", listRole);
return SUCCESS;
}
public String checkUser() throws Exception
{
String username = RequestParamUtil.getString(request, "username");
boolean isExisted = userBO.userExsited(username);
String respCode = "";
if (isExisted)
respCode = "yes";
else
respCode = "no";
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement(ROOT_ELEMENT);
root.addElement("result").addAttribute("value", "" + respCode);
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print(doc.asXML());
out.flush();
out.close();
return null;
}
/**
* 获取指定用户信息
*
* @return
* @throws Exception
*/
public String loadUserById() throws Exception
{
Integer id = RequestParamUtil.getInteger(request, "id");
mapOut = userBO.load(id);
return SUCCESS;
}
/**
* 保存和更新用户信息
*
* @return
* @throws Exception
*/
public String saveUser() throws Exception
{
Map mapIn = PageInputCollector.collectInputMap(request, PAGE_CREATE_USER);
String action = mapIn.get("action").toString();
String result = SUCCESS;
if ("update".equals(action))
{
userBO.update(mapIn);
}
else
{
userBO.insert(mapIn);
}
return result;
}
/**
* 更新用户信息页面初始化
*
* @return
* @throws Exception
*/
public String updateUser() throws Exception
{
Integer id = RequestParamUtil.getInteger(request, "id");
Map result = userBO.initUpdateUser(id);
mapOut.putAll(result);
mapOut.put("action", "update");
return SUCCESS;
}
/**
* 罗列所有用户
*
* @return
* @throws Exception
*/
public String listUsers() throws Exception
{
int begin = getRecordBegin() - 1;
int pageSize = getPageSize();
listOut = new ListWrapper(userBO.listUsers(begin, pageSize));
//设置分页导航信息
int count = userBO.getCount();
setPageInfo(new PageInfo(getCurrPage(), count, pageSize, generateURI()));
return SUCCESS;
}
/**
* 删除指定用户
*
* @return
* @throws Exception
*/
public String removeUser() throws Exception
{
Integer id = RequestParamUtil.getInteger(request, "id");
userBO.remove(id);
return SUCCESS;
}
public String generateURI()
{
// 分页信息:
StringBuffer uri = new StringBuffer();
uri.append(request.getRequestURI() + "?");
uri.append("xxx=" + "xxx");
return uri.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -