usermanageaction.java

来自「一个简单的java邮件系统源码」· Java 代码 · 共 67 行

JAVA
67
字号
package com.easyjweb.action;

import java.util.ArrayList;
import java.util.Collection;

import com.easyjf.util.CommUtil;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.CrudAction;
import com.easyjf.web.tools.DbPageList;

import com.easyjf.web.tools.IPageList;
import com.easyjweb.business.User;

/**
 * 使用添删改查action
 * @author 大峡
 *
 */
public class userManageAction extends CrudAction {
	/**
	 * 查询及分页,通过实现AbstractCrudAction中的抽象方法实现
	 */
	public IPageList doQuery(WebForm form, int currentPage, int pageSize) {
		String scope = "1=1";
		Collection paras = new ArrayList();
		String orderType = CommUtil.null2String(form.get("orderType"));
		String orderField = CommUtil.null2String(form.get("orderField"));
		String userName = CommUtil.null2String(form.get("queryUserName"));
		String tel = CommUtil.null2String(form.get("queryTel"));
		if (!userName.equals("")) {
			scope += " and userName like ?";
			paras.add("%" + userName + "%");
		}
		if (!tel.equals("")) {
			scope += " and tel like ?";
			paras.add("%" + tel + "%");
		}
		if (orderField.equals(""))// 默认按用户名排序
		{
			orderField = "userName";
			orderType = "desc";
		}
		if (!orderField.equals("")) {
			scope += " order by " + orderField;
			if (!orderType.equals(""))
				scope += " " + orderType;
		}
		DbPageList pList = new DbPageList(User.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}

	/**
	 * 这个方法负责根据Form中的数据转换成java对象。
	 * 
	 */
	public Object form2Obj(WebForm form) {
		String cid = (String) form.get("cid");
		User user = null;
		if (cid != null && (!cid.equals("")))
			user = User.read(cid);
		if (user == null)
			user = new User();
		return form.toPo(user);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?