- 添加mybatis依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
- 在启动类上添加扫描注解,值为要扫描的dao,如有多个则逗号隔开
@MapperScan("springboot.learn.dao")
- 编写一个Mapper接口,并添加方法(类名不一定需要以Mapper结尾)
public interface PersonMapper {
@Insert("insert into Person(name,age) values(#{name},#{age})")
public int savePerson(Person person);
}
- 编写service,并在service中直接注入该接口,调用其方法即可