⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basdictaction.java

📁 本系统基本完善了CRM管理系统的各个模块
💻 JAVA
字号:
package com.accp.struts.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.LazyDynaBean;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.accp.util.PageResult;
import com.accp.dao.jb_crm_team0.Imp.BasDictDAO;
import com.accp.entity.jb_crm_team0.BasDict;
import com.accp.service.BasDictService;
import com.accp.struts.form.BasDictForm;

public class BasDictAction extends DispatchAction {
	private BasDictService dictService = null;

	public BasDictService getDictService() {
		return dictService;
	}

	public void setDictService(BasDictService dictService) {
		this.dictService = dictService;
	}

	// 如果没有传递actionType,默认执行这个方法
	protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		System.out.println("默认方法...");
		// 默认去入口
		PrintWriter out = response.getWriter();
		out.print("允许访问");
		return null;
	}

	// 查询数据字典管理
	public ActionForward doList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		System.out.println("查询数据字典管理");
		LazyDynaBean ll = new LazyDynaBean();
		BeanUtils.populate(ll, request.getParameterMap());
		Map paramMap = ll.getMap();
		PageResult pgr = dictService.findAll(paramMap);
		System.out.println("总共有" + pgr.getRowCount() + "条数据字典管理信息");

		String pgrstr = JSONSerializer.toJSON(pgr).toString();
		System.out.println(pgrstr);
		out.print(pgrstr);
		out.close();
		return null;
	}

	// 新建或修改数据字典管理
	public ActionForward doSaveandUpdate(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		BasDict basdict = new BasDict();
		BasDictForm basdform = (BasDictForm) form;
		// 从页面读信息
		basdict.setDictId(basdform.getDictId());
		basdict.setDictType(basdform.getDictType());
		basdict.setDictItem(basdform.getDictItem());
		basdict.setDictValue(basdform.getDictValue());
		basdict.setDictIsEditable(basdform.getDictIsEditable());
		try {
			// 如果数据字典ID是空的话就是新建
			if (dictService.findById(basdform.getDictId()) == false) {
				System.out.print("新建数据字典");
				dictService.add(basdict);
				out.print("{success:true,msg:'增加成功'}");
			}
			// 否则就是修改
			else {
				System.out.print("修改数据字典");
				dictService.update(basdict);
				out.print("{success:true,msg:'修改成功'}");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			out.print("{success:false,data:'系统异常,保存失败'}");
		}

		return null;
	}

	// 删除数据字典管理
	public ActionForward doDelete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		BasDict basdict = dictService.findBydictId(Long.parseLong(request
				.getParameter("dictId")));
		try {
			dictService.delete(basdict);
			out.print("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{success:false,data:'系统异常,保存失败'}");
			// TODO: handle exception
		}

		return null;
	}

}

⌨️ 快捷键说明

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