|
@@ -14,21 +14,23 @@ public class Test1 {
|
14
|
14
|
public void test() throws IOException {
|
15
|
15
|
InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
|
16
|
16
|
SqlSessionFactory sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder().build(resourceAsStream);
|
17
|
|
- SqlSession sqlSession = sqlSessionFactoryBuilder.openSession();
|
|
17
|
+ SqlSession sqlSession = sqlSessionFactoryBuilder.openSession(true);
|
18
|
18
|
// 查询
|
19
|
19
|
// List<AccountEntity> objects = sqlSession.selectList("com.mapper.AccountMapper.findAll");
|
20
|
20
|
// 插入
|
21
|
|
- AccountEntity accountEntity = new AccountEntity();
|
22
|
|
- accountEntity.setUser_name("这");
|
23
|
|
- accountEntity.setBalance(70.4);
|
24
|
|
- sqlSession.insert("com.mapper.AccountMapper.insertOne",accountEntity);
|
|
21
|
+// AccountEntity accountEntity = new AccountEntity();
|
|
22
|
+// accountEntity.setUser_name("这");
|
|
23
|
+// accountEntity.setBalance(70.4);
|
|
24
|
+// sqlSession.insert("com.mapper.AccountMapper.insertOne",accountEntity);
|
25
|
25
|
AccountEntity updateEntity = new AccountEntity();
|
26
|
26
|
updateEntity.setId(9);
|
27
|
27
|
updateEntity.setUser_name("我是");
|
28
|
28
|
updateEntity.setBalance(100.0);
|
29
|
|
- sqlSession.update("com.mapper.AccountMapper.updateOne",updateEntity);
|
|
29
|
+ // namespace + functionName
|
|
30
|
+ sqlSession.update("accountMapper.updateOne",updateEntity);
|
30
|
31
|
// mybatis 如果执行了更新操作需要提交事务
|
31
|
|
- sqlSession.commit();
|
|
32
|
+// sqlSession.commit();
|
|
33
|
+ sqlSession.rollback();
|
32
|
34
|
sqlSession.close();
|
33
|
35
|
}
|
34
|
36
|
}
|