首页>代码>ssm(spring+spring mvc+mybatis)开发家庭理财管理系统>/ffms/src/main/java/com/finance/controller/DatadicController.java
package com.finance.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.finance.entity.Datadic;
import com.finance.entity.PageBean;
import com.finance.service.DatadicService;
import com.finance.util.ResponseUtil;
import com.finance.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 数据字典Controller层
 * 
 * @author 赵鹏(zhaopeng)
 *
 */
@Controller
public class DatadicController {
	
	@Resource
	private DatadicService datadicService;
	
	/**
	 * 数据字典信息页面
	 */
	@RequestMapping("/datadicManage.do")
	public String datadicManage(ModelMap map) {
		List<Datadic> list = datadicService.getDatadicname();
		map.addAttribute("datadicnames", list);
		return "datadicManage";
	}
	
	/**
	 * 查询数据字典集合
	 * 
	 * @param page
	 * @param rows
	 * @param s_datadic
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/datadiclist.do")
	public String list(@RequestParam(value = "page", required = false) String page,
			@RequestParam(value = "rows", required = false) String rows, Datadic s_datadic, HttpServletResponse response)
			throws Exception {
		PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("datadicname", s_datadic.getDatadicname());
		map.put("datadicvalue", StringUtil.formatLike(s_datadic.getDatadicvalue()));
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
		List<Datadic> datadicList = datadicService.findDatadic(map);
		Long total = datadicService.getTotalDatadic(map);
		JSONObject result = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(datadicList);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);
		return null;
	}
	
	/**
	 * 添加与修改数据字典
	 * 
	 * @param datadic
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/datadicsave.do")
	public String save(Datadic datadic, HttpServletResponse response) throws Exception {
		int resultTotal = 0; // 操作的记录条数
		JSONObject result = new JSONObject();
		if (datadic.getId() == null) {
			resultTotal = datadicService.addDatadic(datadic);
		} else {
			resultTotal = datadicService.updateDatadic(datadic);
		}

		if (resultTotal > 0) { // 执行成功
			result.put("errres", true);
			result.put("errmsg", "数据保存成功!");
		} else {
			result.put("errres", false);
			result.put("errmsg", "数据保存失败");
		}
		ResponseUtil.write(response, result);
		return null;
	}

	/**
	 * 删除数据字典
	 * 
	 * @param ids
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/datadicdelete.do")
	public String delete(@RequestParam(value = "ids") String ids, HttpServletResponse response) throws Exception {
		JSONObject result = new JSONObject();
		String[] idsStr = ids.split(",");
		for (int i = 0; i < idsStr.length; i++) {
			datadicService.deleteDatadic(Integer.parseInt(idsStr[i]));
		}
		result.put("errres", true);
		result.put("errmsg", "数据删除成功!");
		ResponseUtil.write(response, result);
		return null;
	}
}
最近下载更多
 LV8 2023年10月23日
hanhan111  LV2 2023年7月14日
jlmarket  LV22 2023年6月9日
1257592068  LV6 2023年6月5日
微信网友_6465435620184064  LV6 2023年5月8日
taowufeng2  LV8 2022年12月12日
l like eat  LV1 2022年11月23日
biesibieke  LV1 2022年10月20日
12cq345  LV6 2022年10月13日
微信网友_6164511365238784  LV7 2022年10月10日
最近浏览更多
可是不知道么  LV23 3月22日
KIKO666 2月21日
暂无贡献等级
森sdfgf  LV8 2月5日
Camellia-while  LV1 1月2日
苏小伟  LV1 2023年12月30日
5fjeoigjo 2023年12月27日
暂无贡献等级
WBelong  LV7 2023年12月25日
fff2003  LV6 2023年12月23日
lin123wk 2023年12月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友