鍍金池/ 問答/Java  數(shù)據(jù)庫  網(wǎng)絡(luò)安全/ Mybatise的Oracle數(shù)據(jù)庫插入問題

Mybatise的Oracle數(shù)據(jù)庫插入問題

在使用Mybatise的時候,我用以下代碼對數(shù)據(jù)庫進(jìn)行操作,沒有報(bào)錯,成功執(zhí)行,但是數(shù)據(jù)庫沒有查找到數(shù)據(jù)

@Test//
    public void testInsertUser(){
        SqlSession sqlSession = sessionFactory.openSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        User user = new User(4, "rose", "男", 12);
        userMapper.insertUser(user);
        sqlSession.commit();
        sqlSession.close();
    };

在日志里面

clipboard.png
求解?。?!
谷歌和百度上好像沒有我這樣的情況,他們類似的問題是沒有提交事務(wù),但是這里我提交了事務(wù),還是不行

回答
編輯回答
毀與悔

找到原因了
Mabitis關(guān)聯(lián)接口的方式操作數(shù)據(jù)庫,在mapper.xml映射文件中,我把<insert></insert>標(biāo)簽寫成了<select></select>標(biāo)簽,沒有報(bào)錯,但是這樣不會返回所更改的行數(shù)


@Test//
    public void testInsertUser(){
        int row = 0;
        SqlSession sqlSession = sessionFactory.openSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        User user = new User(6, "rose", "男", 12);
        row = userMapper.insertUser(user);//這樣就接收不到值,返回的是一個null
        sqlSession.commit();
        sqlSession.close();
        System.out.println(row);
    };

因?yàn)槭遣樵儤?biāo)簽,自然數(shù)據(jù)也就不會被提交

2018年5月7日 21:18