spring mvc事务管理不起作用-备忘
不起作用前代码:
ComusersController.java
... /*注册*/ @RequestMapping(value = "/registration", method = RequestMethod.POST) @ResponseBody public String registration(Map<String, Object> map){ Map<String, Object> comusers = new HashMap<String, Object>(); comusers.put("username", map.get("username")); comusers.put("user_type", 2); comusers.put("is_auth", 1); comusers.put("password", map.get("password")); long time = System.currentTimeMillis(); comusers.put("gmt_modified", time); comusers.put("gmt_create", time); comusers.put("ifdel", map.get("ifdel")); Map<String, Object> comusers_detail = new HashMap<String, Object>(); comusers_detail.put("com_name", map.get("com_name")); comusers_detail.put("com_shortname", map.get("com_shortname")); comusers_detail.put("contact_info", map.get("contact_info")); comusers_detail.put("contact_user", map.get("contact_user")); comusers_detail.put("com_address", map.get("com_address")); comusers_detail.put("com_size", map.get("com_size")); comusers_detail.put("gmt_create", time); comusers_detail.put("gmt_modified", time); long cid = comUserService.register(comusers); comusers_detail.put("cid", cid); return (comusersDetailService.save(comusers_detail)>0 ? "1" : "注册失败"); } ...
ComUserService.java
... @Resource IComUsersDao comUsersDao; @Override public long register(Map<String, Object> map) { return comUsersDao.save(map); } ...
修改成功后代码:
ComusersController.java
... /*注册*/ @RequestMapping(value = "/registration", method = RequestMethod.POST) @ResponseBody public String registration(Map<String, Object> map){ return (comUserService.register(map)>0 ? "1" : "注册失败"); } ...
ComUserService.java
... @Resource IComUsersDao comUsersDao; @Resource IComusersDetailDao comusersDetailDao; @Override public long register(Map<String, Object> map) { Map<String, Object> comusers = new HashMap<String, Object>(); comusers.put("username", map.get("username")); comusers.put("user_type", 2); comusers.put("is_auth", 1); comusers.put("password", map.get("password")); long currentTime = System.currentTimeMillis(); comusers.put("gmt_modified", currentTime); comusers.put("gmt_create", currentTime); comusers.put("ifdel", map.get("ifdel")); Map<String, Object> comusers_detail = new HashMap<String, Object>(); comusers_detail.put("com_name", map.get("com_name")); comusers_detail.put("com_shortname", map.get("com_shortname")); comusers_detail.put("contact_info", map.get("contact_info")); comusers_detail.put("contact_user", map.get("contact_user")); comusers_detail.put("com_address", map.get("com_address")); comusers_detail.put("com_size", map.get("com_size")); comusers_detail.put("gmt_create", currentTime); comusers_detail.put("gmt_modified", currentTime); comusers_detail.put("cid", comUsersDao.save(comusers)); return comusersDetailDao.save(comusers_detail); } ...
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14