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);
	}

...

你可能感兴趣的:(spring mvc)