1. 程式人生 > >Mybatis學習第7節 -- 刪除

Mybatis學習第7節 -- 刪除

pda -c commit osi session batis mysql ssi tsql

接口
int deleteShopById(int id);
映射
<delete id="deleteShopById">
DELETE FROM `tb_shop` WHERE `shop_id` = #{id}
</delete>
測試
@Test
public void testDeleteShopById() {
String template = "刪除結果: %s";
SqlSession session = MyBatisUtil.getSqlSession();
ShopMapper mapper = session.getMapper(ShopMapper.class);

int count = mapper.deleteShopById(42);
session.commit();
session.close();
System.out.printf(template, count);
}
結果
Opening JDBC Connection
Created connection 858423246.
Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@332a7fce]
==> Preparing: DELETE FROM `tb_shop` WHERE `shop_id` = ?
==> Parameters: 42(Integer)
<== Updates: 1
Committing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@332a7fce]
Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@332a7fce]
Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@332a7fce]
Returned connection 858423246 to pool.
刪除結果: 1

Mybatis學習第7節 -- 刪除