MyBatis中增删改操作
作者:互联网
Mapper层代码
<!-- 增加操作 public int insert (Flower fl) -->
<insert id="insert">
insert into flower values(default,#{name},#{price},#{production})
</insert>
<!--修改操作 public int update(Flower fl) -->
<update id="update">
update flower set name=#{name},price=#{price},production=#{production} where id=#{id}
</update>
<!--删除操作 public int delete(int id) -->
<delete id="delete">
delete from flower where id=#{param1} //id= #{arg0} 下标为0的参数 不推荐
</delete>
测试文件
Flower fl =new Flower(6, "随便花123",50, "支付宝");
//【A】添加操作
int update1 = session.insert("com.bjsxt.mapper.FlowerMapper.insert", fl);
// 【B】修改操作
int update2 = session.update("com.bjsxt.mapper.FlowerMapper.update", fl);
// 【C】删除操作
int update3 = session.delete("com.bjsxt.mapper.FlowerMapper.delete", 6);
session.commit();
提交的两种方式
[1].手动:session.commit();
[2].自动:SqlSession session = factory.openSession(true);
标签:mapper,flower,int,增删,session,MyBatis,操作,id,production 来源: https://blog.csdn.net/qq_53609683/article/details/115828764