Java tutorial
/** * * Copyright (c) 1995-2012 Wonders Information Co.,Ltd. * 1518 Lianhang Rd,Shanghai 201112.P.R.C. * All Rights Reserved. * * This software is the confidential and proprietary information of Wonders Group. * (Social Security Department). You shall not disclose such * Confidential Information and shall use it only in accordance with * the terms of the license agreement you entered into with Wonders Group. * * Distributable under GNU LGPL license by gnu.org */ package com.wonders.bud.freshmommy.web.asq.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.wonders.bud.framework.common.page.Page; import com.wonders.bud.framework.common.page.PageUtil; import com.wonders.bud.framework.common.page.PageVO; import com.wonders.bud.framework.common.util.QueryParam; import com.wonders.bud.framework.common.util.RestMsg; import com.wonders.bud.freshmommy.service.asq.model.po.AsqResultPO; import com.wonders.bud.freshmommy.service.asq.service.AsqResultService; import com.wonders.bud.freshmommy.web.asq.vo.AsqResultVO; /** * <p> * Title: freshmommy_[]_[Asq] * </p> * <p> * Description: [AsqController] * </p> * * @author HYH * @version $Revision$ 2015121 * @author (lastest modification by $Author$) * @since 20100901 */ @Controller @RequestMapping("api/results") public class AsqResultController { protected Logger log = Logger.getLogger(QuestionController.class); @Autowired private AsqResultService asqResultService; @RequestMapping(value = "/add", method = RequestMethod.POST) @ResponseBody public RestMsg<Object> addResult(HttpServletRequest request) { RestMsg<Object> rm = new RestMsg<Object>(); // ? String qType = request.getParameter("q_Type"); String month = request.getParameter("b_Month"); String rDesc = request.getParameter("r_rDesc"); if (StringUtils.isBlank(qType)) { rm.errorMsg("?"); return rm; } if (StringUtils.isBlank(month)) { rm.errorMsg("???"); return rm; } if (StringUtils.isBlank(rDesc)) { rm.errorMsg("??"); return rm; } Map<String, Object> map = new HashMap<String, Object>(); map.put("qType", Integer.valueOf(qType)); map.put("month", Integer.valueOf(month)); if (asqResultService.duplicatecheck(null, map)) { rm.errorMsg("????"); return rm; } try { AsqResultPO po = new AsqResultPO(); po.setqType(Integer.valueOf(qType)); po.setMonth(Integer.valueOf(month)); po.setrDesc(rDesc); po = asqResultService.save(po); rm.successMsg("??"); } catch (Exception e) { log.error(e.getLocalizedMessage()); rm.errorMsg("??"); } return rm; } @RequestMapping(method = RequestMethod.GET) @ResponseBody public RestMsg<PageVO<AsqResultVO>> findByPage(HttpServletRequest request) { RestMsg<PageVO<AsqResultVO>> rm = new RestMsg<PageVO<AsqResultVO>>(); String qType = request.getParameter("qType"); String month = request.getParameter("month"); String rDesc = request.getParameter("rDesc"); String row = request.getParameter("row"); String start = request.getParameter("start"); String sortorder = request.getParameter("sord"); String sortfield = request.getParameter("sidx"); try { Map<String, Object> eq = new HashMap<String, Object>(); Map<String, Object> like = new HashMap<String, Object>(); if (StringUtils.isNotBlank(qType)) { eq.put("qType", Integer.valueOf(qType)); } if (StringUtils.isNotBlank(month)) { eq.put("month", Integer.valueOf(month)); } if (StringUtils.isNotBlank(rDesc)) { like.put("rDesc", rDesc); } QueryParam param = new QueryParam(); param.setEq(eq); param.setLike(like); Page<AsqResultPO> page = new Page<AsqResultPO>(); page.setParam(param); PageUtil.pageSplit(page, start, row, sortorder, sortfield, null); page = asqResultService.findByPage(page); PageVO<AsqResultVO> pageVO = new PageVO<AsqResultVO>(); List<AsqResultVO> data = new ArrayList<AsqResultVO>(); List<AsqResultPO> list = page.getResult(); if (null != list && list.size() > 0) { for (AsqResultPO po : list) { AsqResultVO vo = new AsqResultVO(); BeanUtils.copyProperties(vo, po); data.add(vo); } } pageVO.setData(data); PageUtil.pageVOSplit(page, pageVO); rm.setResult(pageVO); rm.successMsg(); } catch (Exception e) { rm.errorMsg("?"); log.error(e.getLocalizedMessage()); } return rm; } @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public RestMsg<Object> delete(HttpServletRequest request) { RestMsg<Object> rm = new RestMsg<Object>(); String sids = request.getParameter("sids"); try { if (StringUtils.isBlank(sids)) { rm.errorMsg("?"); return rm; } String[] ids = sids.split(","); asqResultService.delete(ids); ; rm.successMsg("??"); } catch (Exception e) { rm.errorMsg("?"); log.error(e.getLocalizedMessage()); } return rm; } @RequestMapping(value = "/detail", method = RequestMethod.GET) @ResponseBody public RestMsg<AsqResultVO> getById(HttpServletRequest request) { RestMsg<AsqResultVO> rm = new RestMsg<AsqResultVO>(); String rId = request.getParameter("rId"); try { if (StringUtils.isBlank(rId)) { rm.errorMsg("??"); return rm; } AsqResultPO po = asqResultService.getById(rId); AsqResultVO vo = new AsqResultVO(); BeanUtils.copyProperties(vo, po); rm.setResult(vo); rm.successMsg(); } catch (Exception e) { rm.errorMsg("??"); log.error(e.getLocalizedMessage()); } return rm; } @RequestMapping(value = "/update", method = RequestMethod.POST) @ResponseBody public RestMsg<Object> update(HttpServletRequest request) { RestMsg<Object> rm = new RestMsg<Object>(); String rId = request.getParameter("rId"); String qType = request.getParameter("q_Type"); String month = request.getParameter("b_Month"); String rDesc = request.getParameter("r_rDesc"); ; try { if (StringUtils.isBlank(qType)) { rm.errorMsg("?"); return rm; } if (StringUtils.isBlank(month)) { rm.errorMsg("???"); return rm; } if (StringUtils.isBlank(rDesc)) { rm.errorMsg("??"); return rm; } // if (StringUtils.isBlank(rId)) { rm.errorMsg("?"); return rm; } AsqResultPO po = new AsqResultPO(); po.setrId(rId); po.setqType(Integer.valueOf(qType)); po.setMonth(Integer.valueOf(month)); po.setrDesc(rDesc); po.setStatus(1); po = asqResultService.update(po); rm.successMsg("??"); } catch (Exception e) { rm.errorMsg("?"); log.error(e.getLocalizedMessage()); } return rm; } }