easyui crud java_EasyUI--增删改查

1 packagecom.yuan.web;2

3 importjava.sql.SQLException;4 importjava.util.HashMap;5 importjava.util.List;6 importjava.util.Map;7

8 importjavax.servlet.http.HttpServletRequest;9 importjavax.servlet.http.HttpServletResponse;10

11 importorg.apache.catalina.util.RequestUtil;12

13 importcom.fasterxml.jackson.core.JsonProcessingException;14 importcom.fasterxml.jackson.databind.ObjectMapper;15 importcom.yuan.dao.UserDao;16 importcom.yuan.util.PageBean;17 importcom.yuan.util.ResponseUtil;18 import com.***.framework.ActionSupport;19

20 public class UserAction extendsActionSupport {21

22 private UserDao userDao = newUserDao();23 /**

24 * 登录成功后跳转index.jsp25 *@paramrequest26 *@paramresponse27 *@return

28 */

29 publicString login(HttpServletRequest request,HttpServletResponse response) {30 //系统中是否有当前登录用户

31 Map map = null;32 try{33 map = this.userDao.list(request.getParameterMap(), null).get(0);34 } catch(Exception e) {35 request.setAttribute("msg", "用户不存在");36 return "login";37 }38 try{39 //有就查询用户菜单中间表,获取对应menuid的集合

40 if(map!=null&&map.size()>0) {41 //得到[{Menuid:002,...},{Menuid:003,...}]42 //截成002,003

43 StringBuilder sb= newStringBuilder();44 List> menuByUid = this.userDao.getMenuByUid(request.getParameterMap(), null);45 for (Mapm : menuByUid) {46 sb.append(","+m.get("menuId"));47 }48 request.setAttribute("menuIds", sb.substring(1));49 return "index";50 }else{51 //没有就重新跳回登陆界面,并提示用户不存在

52 request.setAttribute("msg", "用户不存在");53 return "login";54 }55 } catch (InstantiationException | IllegalAccessException |SQLException e) {56 //TODO Auto-generated catch block

57 e.printStackTrace();58 return "login";59 }60

61 }62

63 /**

64 * 数据表格加载方法65 *@paramrequest66 *@paramresponse67 *@return

68 */

69 publicString list(HttpServletRequest request,HttpServletResponse response) {70 ObjectMapper om= newObjectMapper();71 PageBean pageBean = newPageBean();72 pageBean.setRequest(request);73 try{74 List> list = this.userDao.list(request.getParameterMap(), pageBean);75 Map map = new HashMap();76 map.put("total", pageBean.getTotal());77 map.put("rows", list);78 ResponseUtil.write(response,om.writeValueAsString(map));79 } catch(Exception e) {80 //TODO Auto-generated catch block

81 e.printStackTrace();82 }83 return null;84

85 }86

87 /**

88 * form组建提交方法89 *@paramrequest90 *@paramresponse91 *@return

92 */

93 publicString edit(HttpServletRequest request,HttpServletResponse response) {94 try{95 int code=this.userDao.edit(request.getParameterMap());96 ObjectMapper om = newObjectMapper();97 Map map = new HashMap();98 map.put("code", code);99 ResponseUtil.write(response, om.writeValueAsString(map));100 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException |IllegalAccessException101 |SQLException e) {102 //TODO Auto-generated catch block

103 e.printStackTrace();104 } catch(JsonProcessingException e) {105 //TODO Auto-generated catch block

106 e.printStackTrace();107 } catch(Exception e) {108 //TODO Auto-generated catch block

109 e.printStackTrace();110 }111 return null;112

113 }114

115 /**

116 * 新增117 *@paramreq118 *@paramresp119 *@return

120 *@throwsInstantiationException121 *@throwsIllegalAccessException122 *@throwsSQLException123 *@throwsException124 */

125 public String add(HttpServletRequest req,HttpServletResponse resp) throwsInstantiationException, IllegalAccessException, SQLException, Exception {126 int code=this.userDao.add(req.getParameterMap());127 ObjectMapper om = newObjectMapper();128 Map map = new HashMap<>();129 map.put("code", code);130 ResponseUtil.write(resp, om.writeValueAsString(map));131 return null;132 }133

134 /**

135 * 删除136 *@paramreq137 *@paramresp138 *@return

139 *@throwsInstantiationException140 *@throwsIllegalAccessException141 *@throwsSQLException142 *@throwsException143 */

144 public String remove(HttpServletRequest req,HttpServletResponse resp) throwsInstantiationException, IllegalAccessException, SQLException, Exception {145 int code=this.userDao.remove(req.getParameterMap());146 ObjectMapper om = newObjectMapper();147 Map map = new HashMap<>();148 map.put("code", code);149 ResponseUtil.write(resp, om.writeValueAsString(map));150 return null;151 }152

153

154

155 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值