2021.3.30
mybatis的insert
1.编写接口
//insert一个用户
int addUser(User user);
2.编写对应的mapper中的sql语句
<insert id="addUser" parameterType="Tool.MybatisUtils.pojo.User">
insert into mybatis.mybatis (name, password) VALUES (#{name},#{password});
</insert>
3.测试
@Test
public void addUser(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserDao mapper = sqlSession.getMapper(UserDao.class);
int res = mapper.addUser(new User("王二狗","111"));
if(res>0){
System.out.println("插入成功");
}
//提交事务
sqlSession.commit();
sqlSession.close();
}