MyBatis中sqlSession操作數據庫,不報錯但無法實現數據修改(增、改、刪)
阿新 • • 發佈:2018-04-18
修改 () brush light pub clas java bat job
public void addCustomerTest() throws Exception { SqlSession sqlSession = MyBatisUtils.getSession(); CustomerMapper customerMapper = sqlSession.getMapper(CustomerMapper.class); Customer customer = new Customer(); customer.setUsername("111"); customer.setJobs("111"); customer.setPhone("111"); customerMapper.addCustomer(customer); sqlSession.commit();sqlSession.close(); }
數據庫查詢操作可實現,但修改無法實現,且不報錯,出現這種情況的原因之一:
事務忘記提交!
添加代碼sqlSession.commit();
長點心就能少犯錯誤。
MyBatis中sqlSession操作數據庫,不報錯但無法實現數據修改(增、改、刪)