mybatis環境準備概述與注意事項(springboot項目引入三項必要的起步依賴)
項目目錄結構
mybatis基礎操作-刪除
對應EmpMapper(接口)代碼
package com. itheima. mapper ; import org. apache. ibatis. annotations. * ; @Mapper
public interface EmpMapper { @Delete ( "delete from emp where id=#{id}" ) public void delete ( Integer id) ;
}
對應SpringbootMybatisCrudApplicationTests(測試類)代碼
package com. itheima ; import com. itheima. mapper. EmpMapper ;
import org. junit. jupiter. api. Test ;
import org. springframework. beans. factory. annotation. Autowired ;
import org. springframework. boot. test. context. SpringBootTest ; @SpringBootTest
class SpringbootMybatisCrudApplicationTests { @Autowired private EmpMapper empMapper; @Test public void testDelete ( ) { empMapper. delete ( 17 ) ; } }
mybatis基礎操作-日志輸出-可直觀看到預編譯SQL的效果
對應application.properties的配置內容
#下面這些內容是為了讓MyBatis 映射
#指定Mybatis 的Mapper 文件
mybatis. mapper- locations= classpath: mappers
測試結果
預編譯SQL優勢
SQL注入介紹
mybatis參數占位符-(使用‘#{}'才能有SQL預編譯效果)
mybatis參數占位符總結