GZMachinesWeb/.svn/pristine/c8/c83d9f13f1d18f6c64610693f6d...

136 lines
3.4 KiB
Plaintext

package com.bonus.sys.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bonus.sys.AjaxRes;
import com.bonus.sys.BaseController;
import com.bonus.sys.GlobalConst;
import com.bonus.sys.Page;
import com.bonus.sys.beans.PostBean;
import com.bonus.sys.service.PostService;
@Controller
@RequestMapping("/backstage/post/")
public class PostController extends BaseController<PostBean> {
@Autowired
private PostService service;
@RequestMapping("list")
public String index(Model model) {
return "/sys/postlist";
}
@RequestMapping(value = "findByPage", method = RequestMethod.POST)
@ResponseBody
public AjaxRes findByPage(Page<PostBean> page,PostBean o){
AjaxRes ar = getAjaxRes();
try {
Page<PostBean> result = service.findByPage(o, page);
Map<String,Object> p = new HashMap<String,Object>();
p.put("list",result);
ar.setSucceed(p);
} catch (Exception e) {
logger.error(e.toString(),e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
@RequestMapping(value = "find", method = RequestMethod.POST)
@ResponseBody
public AjaxRes find(PostBean o) {
AjaxRes ar = getAjaxRes();
try {
List<PostBean> list = service.find(o);
PostBean station = list.get(0);
ar.setSucceed(station);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
@RequestMapping(value="update", method=RequestMethod.POST)
@ResponseBody
public AjaxRes update(PostBean o){
AjaxRes ar=getAjaxRes();
try {
service.update(o);
ar.setSucceedMsg(GlobalConst.UPDATE_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(),e);
ar.setFailMsg(GlobalConst.UPDATE_FAIL);
}
return ar;
}
@RequestMapping(value="add", method=RequestMethod.POST)
@ResponseBody
public AjaxRes add(PostBean o){
AjaxRes ar=getAjaxRes();
try {
int res = service.insertBean(o);
if(res==1)ar.setSucceedMsg(GlobalConst.SAVE_SUCCEED);
else ar.setFailMsg("登录名已存在");
} catch (Exception e) {
logger.error(e.toString(),e);
ar.setFailMsg(GlobalConst.SAVE_FAIL);
}
return ar;
}
@RequestMapping(value="del", method=RequestMethod.POST)
@ResponseBody
public AjaxRes del(PostBean o){
AjaxRes ar=getAjaxRes();
try {
service.delete(o);
ar.setSucceedMsg(GlobalConst.DEL_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(),e);
ar.setFailMsg(GlobalConst.DEL_FAIL);
}
return ar;
}
@RequestMapping(value="delBatch", method=RequestMethod.POST)
@ResponseBody
public AjaxRes delBatch(String chks){
AjaxRes ar=getAjaxRes();
try {
service.deleteBatch(chks);
ar.setSucceedMsg(GlobalConst.DEL_SUCCEED);
} catch (Exception e) {
logger.error(e.toString(),e);
ar.setFailMsg(GlobalConst.DEL_FAIL);
}
return ar;
}
@RequestMapping(value="findPost",method=RequestMethod.POST)
@ResponseBody
public AjaxRes findAreaType(PostBean o) {
AjaxRes ar = getAjaxRes();
try {
List<PostBean> list = service.findPost(o);
ar.setSucceed(list);
} catch (Exception e) {
logger.error(e.toString(), e);
ar.setFailMsg(GlobalConst.DATA_FAIL);
}
return ar;
}
}