解决mysql LOCK TABLES 后事务无法回滚的问题

在spring mvc+ mybatis中定义了一个事务,事务是service 层的一个方法fun1如

try{

....
lock tables ...
}finally{
unlock tables...;
}

坑来了,这样会导致fun1不会回滚,解决是在Controller层来释放锁,即锁释放不能在fun1中释放,

public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
ModelAndView mav = new ModelAndView();
Result result = new Result();
try {
result = upListService.updataListGoodsEx(code,goodsNumStr,goodsIdStr,teamIdStr,goodsPriceStr,user.getStructId());
} catch (Exception e) {
result.setMsg(e.getMessage());
}finally {
sfm.unlockTable(null);
}


return CheckUtil.returnResult(mav, result.getCode(), result.getMsg()
, result.getData());
}

猜你喜欢

转载自blog.csdn.net/zw521cx/article/details/56847429