Use in mybatis
<insert id="add" parameterType="cn.entity.Computer">
insert INTO MyTable(createModel) VALUES(#{createModel})
</insert>
Wrote this in test class
int count = sqlSession.getMapper(ComputerMapper.class).add(com1);
The result is count=1
However, the inserted data was not found in the database. After looking for it, it turned out to be written
factory.openSession(false);
When setting no auto-commit
Add after the return count
sqlSession.commit();
That's it, commit the transaction.
If the factory.openSession(false) parameter above is changed to true, that is, factory.openSession(true);
Then when 1 is returned, the data is added to the database and automatically submitted