首页>代码>ssm(spring+spring mvc+mybatis)开发家庭理财管理系统>/ffms/src/main/java/com/finance/controller/IncomeController.java
package com.finance.controller; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import com.finance.entity.Datadic; import com.finance.entity.Income; import com.finance.entity.PageBean; import com.finance.entity.User; import com.finance.service.DatadicService; import com.finance.service.IncomeService; import com.finance.service.UserService; import com.finance.util.Constants; import com.finance.util.ResponseUtil; import com.finance.util.StringUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** * 收入Controller层 * * @author 田建路 * */ @Controller public class IncomeController { @Resource private IncomeService incomeService; @Resource private DatadicService datadicService; @Resource private UserService userService; @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); // true:允许输入空值,false:不能为空值 } /** * 收入信息管理页面 */ @RequestMapping("/incomeManage.do") public String incomeManage(ModelMap map, HttpServletRequest request) { List<Datadic> list = datadicService.getDatadicIncome(); map.addAttribute("incomes", list); HttpSession session = request.getSession(); User curuser = (User)session.getAttribute(Constants.currentUserSessionKey); Map<String, Object> userMap = new HashMap<String, Object>(); userMap.put("userid", curuser.getId()); userMap.put("roleid", curuser.getRoleid()); List<User> userlist = userService.getAllUser(userMap); map.addAttribute("allUsers", userlist); return "incomeManage"; } /** * 查询用户收入集合 * * @param page * @param rows * @param s_income * @param response * @return * @throws Exception */ @RequestMapping("/incomelist.do") public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, Income s_income, HttpServletResponse response) throws Exception { PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows)); Map<String, Object> map = new HashMap<String, Object>(); map.put("incomer", StringUtil.formatLike(s_income.getIncomer())); map.put("source", StringUtil.formatLike(s_income.getSource())); map.put("dataid", s_income.getDataid()); map.put("starttime", s_income.getStarttime()); map.put("endtime", s_income.getEndtime()); map.put("roleid", s_income.getRoleid()); map.put("userid", s_income.getUserid()); map.put("start", pageBean.getStart()); map.put("size", pageBean.getPageSize()); List<Income> incomeList = incomeService.findIncome(map); Long total = incomeService.getTotalIncome(map); JSONObject result = new JSONObject(); JSONArray jsonArray = JSONArray.fromObject(incomeList); result.put("rows", jsonArray); result.put("total", total); ResponseUtil.write(response, result); return null; } /** * 添加与修改用户 * * @param income * @param response * @return * @throws Exception */ @RequestMapping("/incomesave.do") public String save(Income income, HttpServletResponse response) throws Exception { int resultTotal = 0; // 操作的记录条数 JSONObject result = new JSONObject(); if (income.getId() == null) { resultTotal = incomeService.addIncome(income); } else { resultTotal = incomeService.updateIncome(income); } 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("/incomedelete.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++) { incomeService.deleteIncome(Integer.parseInt(idsStr[i])); } result.put("errres", true); result.put("errmsg", "数据删除成功!"); ResponseUtil.write(response, result); return null; } }
最近下载更多
zouzou123 LV3
10月21日
lilong007 LV22
9月2日
谯桂生 LV2
6月18日
BruceQ LV14
4月26日
℡ 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日