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参数占位符总结